Backtestsjsouprun-20261006-181938#2614
Template contents can parse incorrectly at EOF and around forms
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
The deciding difference is the issue's headline example, `<template><table><form></table></template>`. Per the HTML spec's "in table" handling of a `form` start tag, the token is ignored when a template is on the stack or the form pointer is set. - **Patch B** follows this rule. It changes the check to `getFormElement() != null || inTemplateContents()`, so the form is dropped. Its test expects `<template><table></table></template>` with no form in the document, which matches WPT `template.dat`. - **Patch A** inverts the condition to `getFormElement() != null && !isParsingTemplateContents()`. As a result it inserts a `<form>` inside the template's table, and its test locks in that non-spec output (`<table><form></form></table>`). This would still fail the corresponding WPT case, so Patch A partly misfixes the issue it targets. **Shared changes.** Both patches: - route the InTable EOF through InBody, - replace the recursive template-closing at EOF with a loop, removing the depth-12 cap, - extend the template checks to template-context fragments for form start and end tags. **Extra correctness work in Patch B.** - It stops the fragment form-ancestor search at a template boundary, so `Element.html()` inside template contents does not pick up an outer form. - It prevents form controls inside template contents from being associated with an outer form pointer. This fits the issue's statement that template forms should not interfere with the surrounding document. - It guards the post-loop reprocess for template fragment contexts. **Tests.** Patch B's tests are broader and spec-aligned: table modes at EOF, depth 40, deep nesting in fragments, and form isolation in both document and fragment parsing. Patch A's tests include an incorrect expectation. Overall, Patch B is more correct and better tested.
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
20m 53s
Wall-clock time in the container
Full test suite
No new failures
2,371 passed · 0 skipped · 2,371 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
141vs 93 merged
Changed lines, ours vs merged
The issue
View on GitHubWhile running the HTML tree-construction tests, I found a couple of related gaps in jsoup’s template handling.
Unclosed templates are not always finished correctly when the input ends, particularly when a template contains a table or when templates are deeply nested.
Forms inside template contents can also interfere with forms in the surrounding document.
For example:
<template><table><form></table></template><input name=outside>
The form belongs to the template contents and should not capture the input that follows the template.
The same rules should apply when setting the contents of a template with Element.html().