From 3f9863bd256a5ed79f250b882024f89e07925364 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Sun, 7 Jun 2026 08:11:53 +0100 Subject: [PATCH 1/4] Update HtmlParser.cs --- OpenDreamClient/Interface/Html/HtmlParser.cs | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/OpenDreamClient/Interface/Html/HtmlParser.cs b/OpenDreamClient/Interface/Html/HtmlParser.cs index 8d3b2904df..69dfad7778 100644 --- a/OpenDreamClient/Interface/Html/HtmlParser.cs +++ b/OpenDreamClient/Interface/Html/HtmlParser.cs @@ -1,6 +1,6 @@ -using System.Text; -using OpenDreamShared.Dream; +using OpenDreamShared.Dream; using Robust.Shared.Utility; +using System.Text; namespace OpenDreamClient.Interface.Html; @@ -33,6 +33,11 @@ void PushCurrentText() { currentText.Clear(); } + void SkipComment() { + while ((i - 2 < 0 || (text[i - 2] != '-' || text[i - 1] != '-' || text[i] != '>')) && text.Length > 2) + i++; + } + for (i = 0; i < text.Length; i++) { char c = text[i]; @@ -98,6 +103,12 @@ void PushCurrentText() { appendTo.Pop(); tags.Pop(); } else { + // If a comment contained other HTML tags, we need to make sure those also + // get skipped. + if (tagType == "!--") { + SkipComment(); + continue; + } if (!isSelfClosing) { tags.Push(tagType); } @@ -123,7 +134,7 @@ void PushCurrentText() { if (insideEntity.StartsWith('#')) { if (int.TryParse(insideEntity.Substring(1), out int result)) { - currentText.Append((char) result); + currentText.Append((char)result); } } else { switch (insideEntity) { From e7d1bd6fb90dc39f01b257d80fbcaf3f67da94e9 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Sun, 7 Jun 2026 11:16:42 +0100 Subject: [PATCH 2/4] Fixes HTML parsing bug for attributes with spaces in them Update HtmlParser.cs --- OpenDreamClient/Interface/Html/HtmlParser.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OpenDreamClient/Interface/Html/HtmlParser.cs b/OpenDreamClient/Interface/Html/HtmlParser.cs index 69dfad7778..f6a9639867 100644 --- a/OpenDreamClient/Interface/Html/HtmlParser.cs +++ b/OpenDreamClient/Interface/Html/HtmlParser.cs @@ -1,6 +1,8 @@ using OpenDreamShared.Dream; using Robust.Shared.Utility; +using System.Linq; using System.Text; +using System.Text.RegularExpressions; namespace OpenDreamClient.Interface.Html; @@ -11,6 +13,9 @@ public static class HtmlParser { private static readonly ISawmill Sawmill; private static readonly HashSet WarnedAttributes = new(); + private static Regex? _attributeMatchRegex = null; + private static Regex AttributeMatchRegex => _attributeMatchRegex ??= new Regex(@"\w+(?:=(?:\w+|""[^""]*""|'[^']*'))?"); + static HtmlParser() { Sawmill = IoCManager.Resolve().GetSawmill("opendream.html_parser"); } @@ -72,7 +77,10 @@ void SkipComment() { } string insideTag = currentText.ToString(); - string[] attributes = insideTag.Split(' ', StringSplitOptions.RemoveEmptyEntries); + string[] attributes = AttributeMatchRegex.Matches(insideTag) + .Where(x => x.Length > 0) + .Select(x => x.Value) + .ToArray(); string tagType = attributes[0].ToLowerInvariant(); currentText.Clear(); From 35591326df7190a3fd7b17290f5b3afdd2ba8d7d Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Sun, 7 Jun 2026 11:24:02 +0100 Subject: [PATCH 3/4] Improves the robustness against completely malformed tags --- OpenDreamClient/Interface/Html/HtmlParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenDreamClient/Interface/Html/HtmlParser.cs b/OpenDreamClient/Interface/Html/HtmlParser.cs index f6a9639867..51cfb5a732 100644 --- a/OpenDreamClient/Interface/Html/HtmlParser.cs +++ b/OpenDreamClient/Interface/Html/HtmlParser.cs @@ -14,7 +14,7 @@ public static class HtmlParser { private static readonly HashSet WarnedAttributes = new(); private static Regex? _attributeMatchRegex = null; - private static Regex AttributeMatchRegex => _attributeMatchRegex ??= new Regex(@"\w+(?:=(?:\w+|""[^""]*""|'[^']*'))?"); + private static Regex AttributeMatchRegex => _attributeMatchRegex ??= new Regex(@"[^ =]+(?:=(?:\w+|""[^""]*""|'[^']*'))?"); static HtmlParser() { Sawmill = IoCManager.Resolve().GetSawmill("opendream.html_parser"); From cce84249a406356c57e4311d96001d8cfc4dcbe2 Mon Sep 17 00:00:00 2001 From: PowerfulBacon <26465327+PowerfulBacon@users.noreply.github.com> Date: Sun, 7 Jun 2026 11:30:39 +0100 Subject: [PATCH 4/4] Apply suggestion from @PowerfulBacon --- OpenDreamClient/Interface/Html/HtmlParser.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OpenDreamClient/Interface/Html/HtmlParser.cs b/OpenDreamClient/Interface/Html/HtmlParser.cs index 51cfb5a732..6be483a5ca 100644 --- a/OpenDreamClient/Interface/Html/HtmlParser.cs +++ b/OpenDreamClient/Interface/Html/HtmlParser.cs @@ -13,7 +13,7 @@ public static class HtmlParser { private static readonly ISawmill Sawmill; private static readonly HashSet WarnedAttributes = new(); - private static Regex? _attributeMatchRegex = null; + private static Regex? _attributeMatchRegex; private static Regex AttributeMatchRegex => _attributeMatchRegex ??= new Regex(@"[^ =]+(?:=(?:\w+|""[^""]*""|'[^']*'))?"); static HtmlParser() {