From 8c4cdee56be0f9e607e1f751886a0e12d1240e73 Mon Sep 17 00:00:00 2001 From: Lukas Gasselsberger | alu-one Date: Mon, 13 Jul 2026 10:53:31 +0200 Subject: [PATCH] Fix bug, where a string stated as content is handled like a path --- src/Fallout.Common/IO/XmlTasks.cs | 2 +- tests/Fallout.Common.Specs/XmlTasksSpecs.cs | 41 +++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tests/Fallout.Common.Specs/XmlTasksSpecs.cs diff --git a/src/Fallout.Common/IO/XmlTasks.cs b/src/Fallout.Common/IO/XmlTasks.cs index 684b0eddb..5305c060f 100644 --- a/src/Fallout.Common/IO/XmlTasks.cs +++ b/src/Fallout.Common/IO/XmlTasks.cs @@ -28,7 +28,7 @@ public static IEnumerable XmlPeekElements(string path, string xpath, p public static IEnumerable XmlPeekElementsFromString(string content, string xpath, params (string prefix, string uri)[] namespaces) { - return XmlPeekElements(XDocument.Load(content), xpath, namespaces); + return XmlPeekElements(XDocument.Parse(content), xpath, namespaces); } public static string XmlPeekSingle(string path, string xpath, params (string prefix, string uri)[] namespaces) diff --git a/tests/Fallout.Common.Specs/XmlTasksSpecs.cs b/tests/Fallout.Common.Specs/XmlTasksSpecs.cs new file mode 100644 index 000000000..94b9f819c --- /dev/null +++ b/tests/Fallout.Common.Specs/XmlTasksSpecs.cs @@ -0,0 +1,41 @@ +using System; +using System.Linq; +using System.Xml; +using Fallout.Common.IO; +using FluentAssertions; +using Xunit; + +namespace Fallout.Common.Specs; + +public class XmlTasksSpecs +{ + [Fact] + public void Loading_from_xml_string_works() + { + var content = @"value"; + var elements = XmlTasks.XmlPeekElementsFromString(content, "/root/element").ToList(); + + elements.Should().HaveCount(1); + elements.Single().Value.Should().Be("value"); + } + + [Fact] + public void Loading_from_file_path_throws() + { + var content = "C:\\temp\\test.xml"; + + Action action = () => XmlTasks.XmlPeekElementsFromString(content, "/root/element"); + + action.Should().Throw(); + } + + [Fact] + public void Loading_from_url_throws() + { + var content = "https://example.com/test.xml"; + + Action action = () => XmlTasks.XmlPeekElementsFromString(content, "/root/element"); + + action.Should().Throw(); + } +}