The Free Software Media System - Server Backend & API
Rescue PlayTo function in case of malformed Xml response (port from 10.8 fix)
SeaEagle19352a243744d
diff --git a/Emby.Dlna/PlayTo/DlnaHttpClient.cs b/Emby.Dlna/PlayTo/DlnaHttpClient.csindex 75ff542dd8..9930f0ede1 100644--- a/Emby.Dlna/PlayTo/DlnaHttpClient.cs+++ b/Emby.Dlna/PlayTo/DlnaHttpClient.cs@@ -2,9 +2,11 @@using System;using System.Globalization;+using System.IO;using System.Net.Http;using System.Net.Mime;using System.Text;+using System.Text.RegularExpressions;using System.Threading;using System.Threading.Tasks;using System.Xml;@@ -54,15 +56,34 @@ namespace Emby.Dlna.PlayToLoadOptions.None,cancellationToken).ConfigureAwait(false);}- catch (XmlException ex)+ catch (XmlException){- _logger.LogError(ex, "Failed to parse response");- if (_logger.IsEnabled(LogLevel.Debug))+ // try correcting the Xml response with common errors+ var xmlString = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);++ // find and replace unescaped ampersands (&)+ Regex regex = new Regex(@"(&(?![a-z]*;))");+ xmlString = regex.Replace(xmlString, @"&");++ try{- _logger.LogDebug("Malformed response: {Content}\n", await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false));+ // retry reading Xml+ var xmlReader = new StringReader(xmlString);+ return await XDocument.LoadAsync(+ xmlReader,+ LoadOptions.None,+ cancellationToken).ConfigureAwait(false);}+ catch (XmlException ex)+ {+ _logger.LogError(ex, "Failed to parse response");+ if (_logger.IsEnabled(LogLevel.Debug))+ {+ _logger.LogDebug("Malformed response: {Content}\n", xmlString);+ }- return null;+ return null;+ }}}