瀏覽代碼

Backport pull request #13092 from jellyfin/release-10.10.z

Fix: handling of <set> elements in NfoParser

Original-merge: f333ef74b3cc8444e12ac1210f94daf59c766969

Merged-by: joshuaboniface <joshua@boniface.me>

Backported-by: Bond_009 <bond.009@outlook.com>
TheMelmacian 4 月之前
父節點
當前提交
51207edf44

+ 10 - 13
MediaBrowser.XbmcMetadata/Parsers/MovieNfoParser.cs

@@ -82,21 +82,13 @@ namespace MediaBrowser.XbmcMetadata.Parsers
 
                         if (!string.IsNullOrWhiteSpace(val) && movie is not null)
                         {
-                            // TODO Handle this better later
-                            if (!val.Contains('<', StringComparison.Ordinal))
+                            try
                             {
-                                movie.CollectionName = val;
+                                ParseSetXml(val, movie);
                             }
-                            else
+                            catch (Exception ex)
                             {
-                                try
-                                {
-                                    ParseSetXml(val, movie);
-                                }
-                                catch (Exception ex)
-                                {
-                                    Logger.LogError(ex, "Error parsing set node");
-                                }
+                                Logger.LogError(ex, "Error parsing set node");
                             }
                         }
 
@@ -139,7 +131,12 @@ namespace MediaBrowser.XbmcMetadata.Parsers
                     // Loop through each element
                     while (!reader.EOF && reader.ReadState == ReadState.Interactive)
                     {
-                        if (reader.NodeType == XmlNodeType.Element)
+                        if (reader.NodeType == XmlNodeType.Text && reader.Depth == 1)
+                        {
+                            movie.CollectionName = reader.Value;
+                            break;
+                        }
+                        else if (reader.NodeType == XmlNodeType.Element)
                         {
                             switch (reader.Name)
                             {

+ 3 - 1
MediaBrowser.XbmcMetadata/Savers/MovieNfoSaver.cs

@@ -115,7 +115,9 @@ namespace MediaBrowser.XbmcMetadata.Savers
             {
                 if (!string.IsNullOrEmpty(movie.CollectionName))
                 {
-                    writer.WriteElementString("set", movie.CollectionName);
+                    writer.WriteStartElement("set");
+                    writer.WriteElementString("name", movie.CollectionName);
+                    writer.WriteEndElement();
                 }
             }
         }

+ 18 - 0
tests/Jellyfin.XbmcMetadata.Tests/Parsers/MovieNfoParserTests.cs

@@ -257,5 +257,23 @@ namespace Jellyfin.XbmcMetadata.Tests.Parsers
 
             Assert.Throws<ArgumentException>(() => _parser.Fetch(result, string.Empty, CancellationToken.None));
         }
+
+        [Fact]
+        public void Parsing_Fields_With_Escaped_Xml_Special_Characters_Success()
+        {
+            var result = new MetadataResult<Video>()
+            {
+                Item = new Movie()
+            };
+
+            _parser.Fetch(result, "Test Data/Lilo & Stitch.nfo", CancellationToken.None);
+            var item = (Movie)result.Item;
+
+            Assert.Equal("Lilo & Stitch", item.Name);
+            Assert.Equal("Lilo & Stitch", item.OriginalTitle);
+            Assert.Equal("Lilo & Stitch Collection", item.CollectionName);
+            Assert.StartsWith(">>", item.Overview, StringComparison.InvariantCulture);
+            Assert.EndsWith("<<", item.Overview, StringComparison.InvariantCulture);
+        }
     }
 }

+ 7 - 0
tests/Jellyfin.XbmcMetadata.Tests/Test Data/Lilo & Stitch.nfo

@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="utf-8" standalone="yes"?>
+<movie>
+  <title>Lilo &amp; Stitch</title>
+  <originaltitle>Lilo &amp; Stitch</originaltitle>
+  <set>Lilo &amp; Stitch Collection</set>
+  <plot>&gt;&gt;As Stitch, a runaway genetic experiment from a faraway planet, wreaks havoc on the Hawaiian Islands, he becomes the mischievous adopted alien "puppy" of an independent little girl named Lilo and learns about loyalty, friendship, and ʻohana, the Hawaiian tradition of family.&lt;&lt;</plot>
+</movie>