From 145856a1f04f83298165d0e59d8e9a7e29854390 Mon Sep 17 00:00:00 2001 From: Richard Van Tassel Date: Tue, 18 Feb 2025 00:54:57 -0500 Subject: [PATCH] Adds html parser check for void elements (#2217) --- OpenDreamClient/Interface/Html/HtmlParser.cs | 36 +++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/OpenDreamClient/Interface/Html/HtmlParser.cs b/OpenDreamClient/Interface/Html/HtmlParser.cs index ef434e83c2..6641c1294f 100644 --- a/OpenDreamClient/Interface/Html/HtmlParser.cs +++ b/OpenDreamClient/Interface/Html/HtmlParser.cs @@ -84,7 +84,8 @@ void PushCurrentText() { } else { tags.Push(tagType); - appendTo.PushTag(new MarkupNode(tagType, null, ParseAttributes(attributes)), selfClosing: attributes[^1] == "/"); + bool isSelfClosing = IsSelfClosing(tagType, attributes); + appendTo.PushTag(new MarkupNode(tagType, null, ParseAttributes(attributes)), selfClosing: isSelfClosing); } break; @@ -139,6 +140,39 @@ void PushCurrentText() { appendTo.Pop(); } + /** + * + * Returns if a tag is written in old self-closing form, or if the tag + * represents a void element, which must have no children + * + */ + private static bool IsSelfClosing(string tagType, string[] attributes) { + if (attributes[^1] == "/") { + return true; + } + + switch (tagType) { + case "area": + case "base": + case "br": + case "col": + case "embed": + case "hr": + case "img": + case "input": + case "link": + case "meta": + case "param": + case "source": + case "track": + case "wbr": + return true; + + default: + return false; + } + } + private static Dictionary ParseAttributes(string[] attributes) { Dictionary parsedAttributes = new();