Skip to content

Commit

Permalink
Removed isindex form autovivification
Browse files Browse the repository at this point in the history
No longer in the spec.
  • Loading branch information
jhy committed Jan 14, 2025
1 parent 72fb596 commit 13f4252
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 45 deletions.
6 changes: 5 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
* Optimized performance of selectors like `#id .class` (and other similar descendant queries) by around 4.6x, by better
balancing the Ancestor evaluator's cost function in the query
planner. [2254](/~https://github.com/jhy/jsoup/issues/2254)
* Removed the legacy parsing rules for `<isindex>` tags, which would autovivify a `form` element with labels. This is no
longer in the spec.

### Bug Fixes

Expand All @@ -46,7 +48,9 @@
exceeded. [2250](/~https://github.com/jhy/jsoup/pull/2250)
* For backwards compatibility, allow `null` InputStream inputs to `Jsoup.parse(InputStream stream, ...)`, by returning
an empty `Document`. [2252](/~https://github.com/jhy/jsoup/issues/2252)
* A `template` tag containing an `li` within an open `li` would be parsed incorrectly, as it was not recognized as a "special" tag (which have additional processing rules). Also, added the SVG and MathML namespace tags to the list of special tags.
* A `template` tag containing an `li` within an open `li` would be parsed incorrectly, as it was not recognized as a "
special" tag (which have additional processing rules). Also, added the SVG and MathML namespace tags to the list of
special tags.

## 1.18.3 (2024-Dec-02)

Expand Down
37 changes: 0 additions & 37 deletions src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java
Original file line number Diff line number Diff line change
Expand Up @@ -474,43 +474,6 @@ private boolean inBodyStartTag(Token t, HtmlTreeBuilder tb) {
else
tb.insertElementFor(startTag);
break;
case "isindex":
// how much do we care about the early 90s?
tb.error(this);
if (tb.getFormElement() != null)
return false;

tb.processStartTag("form");
if (startTag.hasAttribute("action")) {
Element form = tb.getFormElement();
if (form != null && startTag.hasAttribute("action")) {
String action = startTag.attributes.get("action");
form.attributes().put("action", action); // always LC, so don't need to scan up for ownerdoc
}
}
tb.processStartTag("hr");
tb.processStartTag("label");
// hope you like english.
String prompt = startTag.hasAttribute("prompt") ?
startTag.attributes.get("prompt") :
"This is a searchable index. Enter search keywords: ";

tb.process(new Token.Character().data(prompt));

// input
Attributes inputAttribs = new Attributes();
if (startTag.hasAttributes()) {
for (Attribute attr : startTag.attributes) {
if (!inSorted(attr.getKey(), Constants.InBodyStartInputAttribs))
inputAttribs.put(attr);
}
}
inputAttribs.put("name", "isindex");
tb.processStartTag("input", inputAttribs);
tb.processEndTag("label");
tb.processStartTag("hr");
tb.processEndTag("form");
break;
case "textarea":
tb.insertElementFor(startTag);
if (!startTag.isSelfClosing()) {
Expand Down
11 changes: 4 additions & 7 deletions src/test/java/org/jsoup/parser/HtmlParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,7 @@ private static Stream<Arguments> dupeAttributeData() {

@Test public void parseBodyIsIndexNoAttributes() {
// /~https://github.com/jhy/jsoup/issues/1404
String expectedHtml = "<form>\n" +
" <hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label>\n" +
" <hr>\n" +
"</form>";
String expectedHtml = "<isindex></isindex>";
Document doc = Jsoup.parse("<isindex>");
assertEquals(expectedHtml, doc.body().html());

Expand Down Expand Up @@ -1068,8 +1065,8 @@ public void testInvalidTableContents() throws IOException {

@Test public void testNormalisesIsIndex() {
Document doc = Jsoup.parse("<body><isindex action='/submit'></body>");
String html = doc.outerHtml();
assertEquals("<form action=\"/submit\"> <hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label> <hr> </form>",
// There used to be rules so this became: <form action="/submit"> <hr><label>This is a searchable index. Enter search keywords: <input name="isindex"></label> <hr> </form>
assertEquals("<isindex action=\"/submit\"></isindex>",
StringUtil.normaliseWhitespace(doc.body().html()));
}

Expand Down Expand Up @@ -1640,7 +1637,7 @@ private boolean didAddElements(String input) {
// /~https://github.com/jhy/jsoup/issues/1637 | https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38987
Document doc = Jsoup.parse("<template><isindex action>");
assertNotNull(doc);
assertEquals("<template><form><hr><label>This is a searchable index. Enter search keywords: <input name=\"isindex\"></label><hr></form></template>",
assertEquals("<template><isindex action></isindex></template>",
TextUtil.stripNewlines(doc.head().html()));
}

Expand Down

0 comments on commit 13f4252

Please sign in to comment.