Repository: jhy/jsoup
Pull request #2198 (2024-09-02 23:44:30)

Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.8.0 to 3.10.0
Bumps [org.apache.maven.plugins:maven-javadoc-plugin](https://github.com/apache/maven-javadoc-plugin) from 3.8.0 to 3.10.0.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/487e47995424a5090dad5702b92fecaf8893a294"><code>487e479</code></a> [maven-release-plugin] prepare release maven-javadoc-plugin-3.10.0</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/9638a6a76c6db53c3bf8ffbd5cec7318b0e25303"><code>9638a6a</code></a> [MJAVADOC-785] Align plugin implementation with AbstractMavenReport (maven-re...</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/9d339255f160d259a64189d31ab4325f1d3fae4e"><code>9d33925</code></a> [MJAVADOC-784] Upgrade to Doxia 2.0.0 Milestone Stack</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/a11b921429c884c7e9d1aa03092b2c7146508db8"><code>a11b921</code></a> [MJAVADOC-809] Align Mojo class names</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/7c4b467e67b482fc709648b283e7ed2d3b50d042"><code>7c4b467</code></a> Bump org.apache.maven.plugins:maven-plugins from 42 to 43</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/636442b317e5506ca6687375c1d86c7395152f93"><code>636442b</code></a> Improve ITs</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/dbca15ac6c523c6eaa973ef5d733c4a5594c23ba"><code>dbca15a</code></a> Bump org.hamcrest:hamcrest-core from 2.2 to 3.0</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/d02bb88d7a2849bdd39dfdf7a6098859145f42d0"><code>d02bb88</code></a> Bump org.apache.commons:commons-lang3 from 3.15.0 to 3.16.0</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/0a850a16589ff0e1e8379fe841159d04e686acfb"><code>0a850a1</code></a> [MJAVADOC-807] Simplify IT for MJAVADOC-498</li>
<li><a href="https://github.com/apache/maven-javadoc-plugin/commit/43e901fc4b45c0fe868825f49f56866937210646"><code>43e901f</code></a> Improve URL handling</li>
<li>Additional commits viewable in <a href="https://github.com/apache/maven-javadoc-plugin/compare/maven-javadoc-plugin-3.8.0...maven-javadoc-plugin-3.10.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=org.apache.maven.plugins:maven-javadoc-plugin&package-manager=maven&previous-version=3.8.0&new-version=3.10.0)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)


</details>


Patch:
diff --git a/CHANGES.md b/CHANGES.md
index c2280ef6..0981c4f9 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -22,6 +22,8 @@
   character. [2169](https://github.com/jhy/jsoup/issues/2169)
 * When tracking source ranges, a text node following an invalid self-closing element may be left
   untracked.[2175](https://github.com/jhy/jsoup/issues/2175)
+* When a document has no doctype, or a doctype not named `html`, it should be parsed in Quirks
+  Mode. [2197](https://github.com/jhy/jsoup/issues/2197)
 
 ## 1.18.1 (2024-Jul-10)
 
diff --git a/pom.xml b/pom.xml
index 0553d84a..425e994e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -118,7 +118,7 @@
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-javadoc-plugin</artifactId>
-        <version>3.8.0</version>
+        <version>3.10.0</version>
         <configuration>
           <doclint>none</doclint>
           <source>8</source>
diff --git a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java
index f1b2d7b2..470a785a 100644
--- a/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java
+++ b/src/main/java/org/jsoup/parser/HtmlTreeBuilderState.java
@@ -25,18 +25,19 @@ enum HtmlTreeBuilderState {
                 tb.insertCommentNode(t.asComment());
             } else if (t.isDoctype()) {
                 // todo: parse error check on expected doctypes
-                // todo: quirk state check on doctype ids
                 Token.Doctype d = t.asDoctype();
                 DocumentType doctype = new DocumentType(
                     tb.settings.normalizeTag(d.getName()), d.getPublicIdentifier(), d.getSystemIdentifier());
                 doctype.setPubSysKey(d.getPubSysKey());
                 tb.getDocument().appendChild(doctype);
                 tb.onNodeInserted(doctype);
-                if (d.isForceQuirks())
+                // todo: quirk state check on more doctype ids, if deemed useful (most are ancient legacy and presumably irrelevant)
+                if (d.isForceQuirks() || !doctype.name().equals("html") || doctype.publicId().equalsIgnoreCase("HTML"))
                     tb.getDocument().quirksMode(Document.QuirksMode.quirks);
                 tb.transition(BeforeHtml);
             } else {
                 // todo: check not iframe srcdoc
+                tb.getDocument().quirksMode(Document.QuirksMode.quirks); // missing doctype
                 tb.transition(BeforeHtml);
                 return tb.process(t); // re-process token
             }


Test patch:
diff --git a/src/test/java/org/jsoup/parser/HtmlParserTest.java b/src/test/java/org/jsoup/parser/HtmlParserTest.java
index 7fa7a67a..a67003a8 100644
--- a/src/test/java/org/jsoup/parser/HtmlParserTest.java
+++ b/src/test/java/org/jsoup/parser/HtmlParserTest.java
@@ -1888,4 +1888,24 @@ public class HtmlParserTest {
         img.ownerDocument().outputSettings().charset("ascii");
         assertEquals("<img multi=\"&#x1f4af;\" single=\"&#x1f4af;\" hexsingle=\"&#x1f4af;\">", img.outerHtml());
     }
+
+    @Test void tableInPInQuirksMode() {
+        // https://github.com/jhy/jsoup/issues/2197
+        String html = "<p><span><table><tbody><tr><td><span>Hello table data</span></td></tr></tbody></table></span></p>";
+        Document doc = Jsoup.parse(html);
+        assertEquals(Document.QuirksMode.quirks, doc.quirksMode());
+        assertEquals(
+            "<p><span><table><tbody><tr><td><span>Hello table data</span></td></tr></tbody></table></span></p>", // quirks, allows table in p
+            TextUtil.normalizeSpaces(doc.body().html())
+        );
+
+        // doctype set, no quirks
+        html ="<!DOCTYPE html><p><span><table><tbody><tr><td><span>Hello table data</span></td></tr></tbody></table></span></p>";
+        doc = Jsoup.parse(html);
+        assertEquals(Document.QuirksMode.noQuirks, doc.quirksMode());
+        assertEquals(
+            "<p><span></span></p><table><tbody><tr><td><span>Hello table data</span></td></tr></tbody></table><p></p>", // no quirks, p gets closed
+            TextUtil.normalizeSpaces(doc.body().html())
+        );
+    }
 }