1
0
Fork 0
mirror of https://github.com/lidarr/Lidarr synced 2024-12-25 01:02:05 +00:00

Replace '&' with its XML encoded equivalent, before parsing XML.

Added test to check for proper XML parsing with illegal characters.
This commit is contained in:
Mark McDowall 2011-09-28 21:39:05 -07:00
parent fd205d3d57
commit 7ca59b92aa
2 changed files with 34 additions and 1 deletions

View file

@ -271,6 +271,39 @@ public void GetXbmcSeriesPath_false()
Assert.AreEqual("", result);
}
[Test]
public void GetXbmcSeriesPath_special_characters()
{
//Setup
var mocker = new AutoMoqer(MockBehavior.Strict);
var queryResult = @"<xml><record><field>smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/</field></record></xml>";
var host = "localhost:8080";
var username = "xbmc";
var password = "xbmc";
var setResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat(webheader;false;webfooter;false;header;<xml>;footer;</xml>;opentag;<tag>;closetag;</tag>;closefinaltag;false)";
var resetResponseUrl = "http://localhost:8080/xbmcCmds/xbmcHttp?command=SetResponseFormat()";
var query = String.Format("http://localhost:8080/xbmcCmds/xbmcHttp?command=QueryVideoDatabase(select path.strPath from path, tvshow, tvshowlinkpath where tvshow.c12 = 79488 and tvshowlinkpath.idShow = tvshow.idShow and tvshowlinkpath.idPath = path.idPath)");
//var fakeUdpProvider = mocker.GetMock<EventClient>();
var fakeHttp = mocker.GetMock<HttpProvider>();
fakeHttp.Setup(s => s.DownloadString(setResponseUrl, username, password)).Returns("<xml><tag>OK</xml>");
fakeHttp.Setup(s => s.DownloadString(resetResponseUrl, username, password)).Returns(@"<html>
<li>OK
</html>");
fakeHttp.Setup(s => s.DownloadString(query, username, password)).Returns(queryResult);
//Act
var result = mocker.Resolve<XbmcProvider>().GetXbmcSeriesPath(host, 79488, username, username);
//Assert
mocker.VerifyAllMocks();
result.Should().Be("smb://xbmc:xbmc@HOMESERVER/TV/Law & Order- Special Victims Unit/");
}
[Test]
public void Clean()
{

View file

@ -187,7 +187,7 @@ public virtual string GetXbmcSeriesPath(string host, int seriesId, string userna
if (String.IsNullOrEmpty(response))
return String.Empty;
var xDoc = XDocument.Load(new StringReader(response));
var xDoc = XDocument.Load(new StringReader(response.Replace("&", "&amp;")));
var xml = (from x in xDoc.Descendants("xml") select x).FirstOrDefault();
if (xml == null)