diff --git a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs index a0c2105a0..cc3829cd7 100644 --- a/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs +++ b/src/NzbDrone.Core/Indexers/Newznab/NewznabRssParser.cs @@ -13,7 +13,7 @@ namespace NzbDrone.Core.Indexers.Newznab protected override bool PreProcess(IndexerResponse indexerResponse) { - var xdoc = XDocument.Parse(indexerResponse.Content); + var xdoc = LoadXmlDocument(indexerResponse); var error = xdoc.Descendants("error").FirstOrDefault(); if (error == null) return true; diff --git a/src/NzbDrone.Core/Indexers/RssParser.cs b/src/NzbDrone.Core/Indexers/RssParser.cs index cc7edd0ba..0bdaabd00 100644 --- a/src/NzbDrone.Core/Indexers/RssParser.cs +++ b/src/NzbDrone.Core/Indexers/RssParser.cs @@ -42,30 +42,48 @@ namespace NzbDrone.Core.Indexers return releases; } - using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true })) + var document = LoadXmlDocument(indexerResponse); + var items = GetItems(document); + + foreach (var item in items) { - var document = XDocument.Load(xmlTextReader); - var items = GetItems(document); + try + { + var reportInfo = ProcessItem(item); - foreach (var item in items) + releases.AddIfNotNull(reportInfo); + } + catch (Exception itemEx) { - try - { - var reportInfo = ProcessItem(item); - - releases.AddIfNotNull(reportInfo); - } - catch (Exception itemEx) - { - itemEx.Data.Add("Item", item.Title()); - _logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx); - } + itemEx.Data.Add("Item", item.Title()); + _logger.ErrorException("An error occurred while processing feed item from " + indexerResponse.Request.Url, itemEx); } } return releases; } + protected virtual XDocument LoadXmlDocument(IndexerResponse indexerResponse) + { + try + { + using (var xmlTextReader = XmlReader.Create(new StringReader(indexerResponse.Content), new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, IgnoreComments = true })) + { + return XDocument.Load(xmlTextReader); + } + } + catch (XmlException ex) + { + var contentSample = indexerResponse.Content.Substring(0, Math.Min(indexerResponse.Content.Length, 512)); + _logger.Debug("Truncated response content (originally {0} characters): {1}", indexerResponse.Content.Length, contentSample); + + ex.Data.Add("ContentLength", indexerResponse.Content.Length); + ex.Data.Add("ContentSample", contentSample); + + throw; + } + } + protected virtual ReleaseInfo CreateNewReleaseInfo() { return new ReleaseInfo();