From 1326624d275e29e18fa422e0bc8ca22fc81b7820 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Wed, 19 Jul 2017 15:53:47 -0400 Subject: [PATCH] strip invalid xml chars --- MediaBrowser.Api/Playback/StreamState.cs | 2 +- .../Savers/BaseNfoSaver.cs | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/MediaBrowser.Api/Playback/StreamState.cs b/MediaBrowser.Api/Playback/StreamState.cs index 2cf7d81af..eecc12432 100644 --- a/MediaBrowser.Api/Playback/StreamState.cs +++ b/MediaBrowser.Api/Playback/StreamState.cs @@ -80,7 +80,7 @@ namespace MediaBrowser.Api.Playback return 6; } - return 10; + return 6; } if (IsSegmentedLiveStream) diff --git a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs index cf7c25584..5015dfbf9 100644 --- a/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs +++ b/MediaBrowser.XbmcMetadata/Savers/BaseNfoSaver.cs @@ -16,9 +16,10 @@ using System.Globalization; using System.IO; using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Threading; using System.Xml; - +using MediaBrowser.Controller.Extensions; using MediaBrowser.Model.Extensions; using MediaBrowser.Model.IO; using MediaBrowser.Model.Xml; @@ -353,7 +354,8 @@ namespace MediaBrowser.XbmcMetadata.Savers if (!string.IsNullOrEmpty(stream.Language)) { - writer.WriteElementString("language", stream.Language); + // https://emby.media/community/index.php?/topic/49071-nfo-not-generated-on-actualize-or-rescan-or-identify + writer.WriteElementString("language", RemoveInvalidXMLChars(stream.Language)); } var scanType = stream.IsInterlaced ? "interlaced" : "progressive"; @@ -422,6 +424,19 @@ namespace MediaBrowser.XbmcMetadata.Savers writer.WriteEndElement(); } + // filters control characters but allows only properly-formed surrogate sequences + private static Regex _invalidXMLChars = new Regex( + @"(? + /// removes any unusual unicode characters that can't be encoded into XML + /// + public static string RemoveInvalidXMLChars(string text) + { + if (string.IsNullOrEmpty(text)) return string.Empty; + return _invalidXMLChars.Replace(text, string.Empty); + } + public const string DateAddedFormat = "yyyy-MM-dd HH:mm:ss"; ///