Backtestsjsouprun-20261006-181938#2621
Align void elements list to spec
Better
Our patch was judged better than the merged fix.
In this judgment, Patch A = our agent, Patch B = the merged fix.
Both patches make the same core fix. They drop `command`, `device`, and `menuitem` from the known tags and void tags in TagSet. They also drop `command` from the InHeadEmpty and InBodyStartToHead lists in HtmlTreeBuilderState. So both resolve the issue equally at its root. The difference is in tests and extra changes. Patch A adds tests aimed directly at the issue: - a parameterized parse test showing each obsolete tag now holds content and needs an end tag; - a test that `<command>` in head breaks out into body and is no longer redirected to head processing from body; - a TagTest check that these tags are now unknown, not empty and not self-closing, while real spec void elements stay void. These tests would fail before the change and pass after it. Patch B adds no tests for `command`, `device`, or `menuitem`. Its only new test covers a separate change: it removes the `!tag.isKnownTag()` shortcut in InBody so unknown tags rebuild active formatting elements. That may be spec-aligned, but it goes beyond the issue's ask. It changes parsing for every custom or unknown tag, which adds risk and hides the actual fix. Its single test covers only that side change. With equal correctness on the issue, Patch A's focused and meaningful tests, and its smaller blast radius, make it the better fix.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
9m
Wall-clock time in the container
Full test suite
No new failures
2,389 passed · 0 skipped · 2,389 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
49vs 18 merged
Changed lines, ours vs merged
The issue
View on GitHubhttps://html.spec.whatwg.org/multipage/syntax.html#void-elements
We have definitions for command, device, and menuitem, but these are no longer in the spec and should not be parsed specifically.
The two patches
Our patch+44 −5
CHANGES.mdindex 5525e0eb..34142480 100644@@ -25,6 +25,7 @@ * Fixed handling of null characters and initial newlines in HTML to better match the HTML spec, including `pre`, `listing`, and `textarea` elements. Leading newlines in these elements' text are preserved when saving and reparsing HTML. [#2616](https://github.com/jhy/jsoup/pull/2616) * Fixed several HTML parsing edge cases across malformed doctypes, misplaced text in tables, and whitespace in framesets to match the HTML spec. [#2618](https://github.com/jhy/jsoup/pull/2618) * If a HTML void element ends up with children (via DOM manipulation), those are no longer serialized in `html()`. [#2619](https://github.com/jhy/jsoup/issues/2619) +* Aligned the void elements list to the HTML spec. The obsolete `command`, `device`, and `menuitem` tags are no longer treated as void (or `command` as head) elements, and are parsed as ordinary elements that may hold content. ## 1.23.2 (2026-Aug-26) src/main/java/org/jsoup/parser/HtmlTreeBuilderState.javaindex 16b8dc13..4a54c8f3 100644@@ -1772,12 +1772,12 @@ enum HtmlTreeBuilderState { // lists of tags to search through static final class Constants {- static final String[] InHeadEmpty = new String[]{"base", "basefont", "bgsound", "command", "link"};+ static final String[] InHeadEmpty = new String[]{"base", "basefont", "bgsound", "link"}; static final String[] InHeadRaw = new String[]{"noframes", "style"}; static final String[] InHeadEnd = new String[]{"body", "br", "html"}; static final String[] AfterHeadBody = new String[]{"body", "br", "html"}; static final String[] BeforeHtmlToHead = new String[]{"body", "br", "head", "html", };- static final String[] InBodyStartToHead = new String[]{"base", "basefont", "bgsound", "command", "link", "meta", "noframes", "script", "style", "template", "title"};+ static final String[] InBodyStartToHead = new String[]{"base", "basefont", "bgsound", "link", "meta", "noframes", "script", "style", "template", "title"}; static final String[] InBodyStartPClosers = new String[]{"address", "article", "aside", "blockquote", "center", "details", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section", "summary", "ul"};src/main/java/org/jsoup/parser/TagSet.javaindex 6309789d..d5c4b49a 100644@@ -253,7 +253,7 @@ public class TagSet { "q", "sub", "sup", "bdo", "iframe", "embed", "span", "input", "select", "textarea", "label", "audio", "video", "canvas", "optgroup", "option", "legend", "datalist", "keygen", "output", "progress", "meter", "area", "param", "source", "track",- "summary", "command", "device", "basefont", "bgsound", "menuitem", "data", "bdi", "s", "strike", "nobr",+ "summary", "basefont", "bgsound", "data", "bdi", "s", "strike", "nobr", "ins", "del", "button", "picture", "slot", "rb", // deprecated but still known / special handling };@@ -261,8 +261,8 @@ public class TagSet { "title", "p", "h1", "h2", "h3", "h4", "h5", "h6", "pre", "address", "li", "th", "td", "script", "style" }; String[] voidTags = {- "meta", "link", "base", "frame", "img", "br", "wbr", "embed", "hr", "input", "keygen", "col", "command",- "device", "area", "basefont", "bgsound", "menuitem", "param", "source", "track"+ "meta", "link", "base", "frame", "img", "br", "wbr", "embed", "hr", "input", "keygen", "col",+ "area", "basefont", "bgsound", "param", "source", "track" }; String[] preserveWhitespaceTags = { "pre", "listing", "plaintext", "title", "textarea", "script"src/test/java/org/jsoup/parser/HtmlParserTest.javaindex 6c807520..fc41f5a2 100644@@ -3072,4 +3072,29 @@ public class HtmlParserTest { assertEquals("Two", paragraph.text()); } }++ @ParameterizedTest+ @ValueSource(strings = {"command", "device", "menuitem"})+ void obsoleteVoidTagsParseAsNormalElements(String tag) {+ // these were removed from the spec's void elements; they should hold content and need an end tag+ Document doc = Jsoup.parse("<div><" + tag + ">One <b>Two</b></" + tag + "> Three</div>");+ Element el = doc.expectFirst(tag);+ assertFalse(el.tag().isEmpty());+ assertEquals("One Two", el.text());+ assertEquals(2, el.childNodeSize());+ assertEquals("<div><" + tag + ">One <b>Two</b></" + tag + "> Three</div>", TextUtil.stripNewlines(doc.body().html()));+ }++ @Test+ void commandInHeadIsNotHeadContent() {+ // <command> is no longer handled as a head element, so it breaks out of head into body+ Document doc = Jsoup.parse("<html><head><title>T</title><command>Cmd</command></head><body><p>P</p></body></html>");+ assertNull(doc.head().selectFirst("command"));+ Element command = doc.body().expectFirst("command");+ assertEquals("Cmd", command.text());++ // and in body, it is not moved to head processing+ Document doc2 = Jsoup.parse("<body><p>One<command>Two</command></p></body>");+ assertEquals("<p>One<command>Two</command></p>", TextUtil.stripNewlines(doc2.body().html()));+ } }src/test/java/org/jsoup/parser/TagTest.javaindex ef8b7383..bc9b4b82 100644@@ -299,4 +299,17 @@ public class TagTest { assertNotEquals(p1, p2); p2.options = p1.options; }++ @Test void obsoleteVoidTagsAreNotKnown() {+ for (String name : new String[]{"command", "device", "menuitem"}) {+ Tag tag = Tag.valueOf(name);+ assertFalse(tag.isKnownTag(), name);+ assertFalse(tag.isEmpty(), name);+ assertFalse(tag.isSelfClosing(), name);+ }+ // spec void elements remain void+ for (String name : new String[]{"area", "base", "br", "col", "embed", "hr", "img", "input", "link", "meta", "source", "track", "wbr"}) {+ assertTrue(Tag.valueOf(name).isEmpty(), name);+ }+ } }
Merged fix · PR #+11 −7
CHANGES.mdindex 5525e0eb..f42ddbff 100644@@ -25,6 +25,7 @@ * Fixed handling of null characters and initial newlines in HTML to better match the HTML spec, including `pre`, `listing`, and `textarea` elements. Leading newlines in these elements' text are preserved when saving and reparsing HTML. [#2616](https://github.com/jhy/jsoup/pull/2616) * Fixed several HTML parsing edge cases across malformed doctypes, misplaced text in tables, and whitespace in framesets to match the HTML spec. [#2618](https://github.com/jhy/jsoup/pull/2618) * If a HTML void element ends up with children (via DOM manipulation), those are no longer serialized in `html()`. [#2619](https://github.com/jhy/jsoup/issues/2619) +* Removed the old `command`, `device`, and `menuitem` tags, as they are no longer in the HTML spec. [#2621](https://github.com/jhy/jsoup/issues/2621) ## 1.23.2 (2026-Aug-26) src/main/java/org/jsoup/parser/HtmlTreeBuilderState.javaindex 16b8dc13..ab7e277e 100644@@ -623,8 +623,6 @@ enum HtmlTreeBuilderState { TokeniserState textState = tag.textState(); if (textState != null) { // custom rcdata or rawtext (if we were in head, will have auto-transitioned here) HandleTextState(startTag, tb, textState);- } else if (!tag.isKnownTag()) { // no other special rules for custom tags- tb.insertElementFor(startTag); } else if (inSorted(name, Constants.InBodyStartPClosers)) { if (tb.inButtonScope("p")) tb.processEndTag("p"); tb.insertElementFor(startTag);@@ -1772,12 +1770,12 @@ enum HtmlTreeBuilderState { // lists of tags to search through static final class Constants {- static final String[] InHeadEmpty = new String[]{"base", "basefont", "bgsound", "command", "link"};+ static final String[] InHeadEmpty = new String[]{"base", "basefont", "bgsound", "link"}; static final String[] InHeadRaw = new String[]{"noframes", "style"}; static final String[] InHeadEnd = new String[]{"body", "br", "html"}; static final String[] AfterHeadBody = new String[]{"body", "br", "html"}; static final String[] BeforeHtmlToHead = new String[]{"body", "br", "head", "html", };- static final String[] InBodyStartToHead = new String[]{"base", "basefont", "bgsound", "command", "link", "meta", "noframes", "script", "style", "template", "title"};+ static final String[] InBodyStartToHead = new String[]{"base", "basefont", "bgsound", "link", "meta", "noframes", "script", "style", "template", "title"}; static final String[] InBodyStartPClosers = new String[]{"address", "article", "aside", "blockquote", "center", "details", "dir", "div", "dl", "fieldset", "figcaption", "figure", "footer", "header", "hgroup", "menu", "nav", "ol", "p", "section", "summary", "ul"};src/main/java/org/jsoup/parser/TagSet.javaindex 6309789d..d5c4b49a 100644@@ -253,7 +253,7 @@ public class TagSet { "q", "sub", "sup", "bdo", "iframe", "embed", "span", "input", "select", "textarea", "label", "audio", "video", "canvas", "optgroup", "option", "legend", "datalist", "keygen", "output", "progress", "meter", "area", "param", "source", "track",- "summary", "command", "device", "basefont", "bgsound", "menuitem", "data", "bdi", "s", "strike", "nobr",+ "summary", "basefont", "bgsound", "data", "bdi", "s", "strike", "nobr", "ins", "del", "button", "picture", "slot", "rb", // deprecated but still known / special handling };@@ -261,8 +261,8 @@ public class TagSet { "title", "p", "h1", "h2", "h3", "h4", "h5", "h6", "pre", "address", "li", "th", "td", "script", "style" }; String[] voidTags = {- "meta", "link", "base", "frame", "img", "br", "wbr", "embed", "hr", "input", "keygen", "col", "command",- "device", "area", "basefont", "bgsound", "menuitem", "param", "source", "track"+ "meta", "link", "base", "frame", "img", "br", "wbr", "embed", "hr", "input", "keygen", "col",+ "area", "basefont", "bgsound", "param", "source", "track" }; String[] preserveWhitespaceTags = { "pre", "listing", "plaintext", "title", "textarea", "script"src/test/java/org/jsoup/parser/HtmlParserTest.javaindex 6c807520..6fd84ae2 100644@@ -607,6 +607,11 @@ public class HtmlParserTest { assertEquals("there", foos.last().text()); } + @Test public void unknownTagsReconstructFormattingElements() {+ Document doc = Jsoup.parse("<p><b></p><foo>");+ assertEquals("<p><b></b></p><b><foo></foo></b>", TextUtil.stripNewlines(doc.body().html()));+ }+ @Test public void handlesUnknownInlineTags() { String h = "<p><cust>Test</cust></p><p><cust><cust>Test</cust></cust></p>"; Document doc = Jsoup.parseBodyFragment(h);