Repository: jhy/jsoup
Pull request #2176 (2024-07-22 23:09:26)

Bump com.github.siom79.japicmp:japicmp-maven-plugin from 0.21.2 to 0.22.0
Bumps [com.github.siom79.japicmp:japicmp-maven-plugin](https://github.com/siom79/japicmp) from 0.21.2 to 0.22.0.
<details>
<summary>Commits</summary>
<ul>
<li><a href="https://github.com/siom79/japicmp/commit/56996bab84011591a6b6edcc2709dfe8c5649043"><code>56996ba</code></a> [maven-release-plugin] prepare release japicmp-base-0.22.0</li>
<li><a href="https://github.com/siom79/japicmp/commit/3a60b0a0a8150bb1bdd71aab376a17250718df07"><code>3a60b0a</code></a> version 0.22.0-SNAPSHOT</li>
<li><a href="https://github.com/siom79/japicmp/commit/17b89ebb109dee5803441876c8ea114e2a6cd17c"><code>17b89eb</code></a> [maven-release-plugin] prepare release japicmp-base-0.22.0</li>
<li><a href="https://github.com/siom79/japicmp/commit/d8d72084016d6272c00bc837d4bd0a4fbd647901"><code>d8d7208</code></a> version 0.22.0-SNAPSHOT</li>
<li><a href="https://github.com/siom79/japicmp/commit/1890598cf6c3cb19c6d2679c4830f0825d7e7d2a"><code>1890598</code></a> [maven-release-plugin] prepare for next development iteration</li>
<li><a href="https://github.com/siom79/japicmp/commit/2d4f359c04bf23bc570580e7906d706baefe8c02"><code>2d4f359</code></a> [maven-release-plugin] prepare release japicmp-base-0.22.1</li>
<li><a href="https://github.com/siom79/japicmp/commit/99c10b5723c76e301513dd33aca1f039c5faf3ef"><code>99c10b5</code></a> Merge remote-tracking branch 'origin/master'</li>
<li><a href="https://github.com/siom79/japicmp/commit/5a3b62b152954e4cfddc6011e3d92d41699dbe8e"><code>5a3b62b</code></a> Upgrade actions/checkout and actions/setup-java</li>
<li><a href="https://github.com/siom79/japicmp/commit/d2718ce185fd12f64c173d78aa57031fea6e085e"><code>d2718ce</code></a> [maven-release-plugin] prepare for next development iteration</li>
<li><a href="https://github.com/siom79/japicmp/commit/7e0304cf1a44de5451980a619c859c692a6a9abc"><code>7e0304c</code></a> [maven-release-plugin] prepare release japicmp-base-0.22.0</li>
<li>Additional commits viewable in <a href="https://github.com/siom79/japicmp/compare/japicmp-base-0.21.2...japicmp-base-0.22.0">compare view</a></li>
</ul>
</details>
<br />


[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=com.github.siom79.japicmp:japicmp-maven-plugin&package-manager=maven&previous-version=0.21.2&new-version=0.22.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 2995fe15..059c903a 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -10,6 +10,8 @@
 
 * `Element.cssSelector()` would fail if the element's class contained a `*`
   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)
 
 ## 1.18.1 (2024-Jul-10)
 
diff --git a/pom.xml b/pom.xml
index 7d88aac8..23d11a08 100644
--- a/pom.xml
+++ b/pom.xml
@@ -228,7 +228,7 @@
         <!-- API version compat check - https://siom79.github.io/japicmp/ -->
         <groupId>com.github.siom79.japicmp</groupId>
         <artifactId>japicmp-maven-plugin</artifactId>
-        <version>0.21.2</version>
+        <version>0.22.0</version>
         <configuration>
           <!-- hard code previous version; can't detect when running stateless on build server -->
           <oldVersion>
@@ -432,7 +432,7 @@
       <!-- org.jspecify.annotations.nonnull, with Apache 2 license. Build time only. -->
       <groupId>org.jspecify</groupId>
       <artifactId>jspecify</artifactId>
-      <version>0.3.0</version>
+      <version>1.0.0</version>
       <scope>provided</scope>
     </dependency>
   </dependencies>
diff --git a/src/main/java/org/jsoup/parser/Tokeniser.java b/src/main/java/org/jsoup/parser/Tokeniser.java
index 2416a66d..ff3bfa4f 100644
--- a/src/main/java/org/jsoup/parser/Tokeniser.java
+++ b/src/main/java/org/jsoup/parser/Tokeniser.java
@@ -49,8 +49,7 @@ final class Tokeniser {
     @Nullable private String lastStartTag; // the last start tag emitted, to test appropriate end tag
     @Nullable private String lastStartCloseSeq; // "</" + lastStartTag, so we can quickly check for that in RCData
 
-    private static final int Unset = -1;
-    private int markupStartPos, charStartPos = 0; // reader pos at the start of markup / characters. updated on state transition. Initialized to start (0), but set to Unset after emissions.
+    private int markupStartPos, charStartPos = 0; // reader pos at the start of markup / characters. markup updated on state transition, char on token emit.
 
     Tokeniser(TreeBuilder treeBuilder) {
         tagPending = startPending  = new Token.StartTag(treeBuilder);
@@ -90,7 +89,7 @@ final class Tokeniser {
         isEmitPending = true;
         token.startPos(markupStartPos);
         token.endPos(reader.pos());
-        charStartPos = Unset;
+        charStartPos = reader.pos(); // update char start when we complete a token emit
 
         if (token.type == Token.TokenType.StartTag) {
             Token.StartTag startTag = (Token.StartTag) token;
@@ -158,15 +157,9 @@ final class Tokeniser {
     }
 
     void transition(TokeniserState newState) {
-        // track markup / data position on state transitions
-        switch (newState) {
-            case TagOpen:
-                markupStartPos = reader.pos();
-                break;
-            case Data:
-                if (charStartPos == Unset) // don't reset when we are jumping between e.g data -> char ref -> data
-                    charStartPos = reader.pos();
-        }
+        // track markup position on state transitions
+        if (newState == TokeniserState.TagOpen)
+            markupStartPos = reader.pos();
 
         this.state = newState;
     }


Test patch:
diff --git a/src/test/java/org/jsoup/parser/PositionTest.java b/src/test/java/org/jsoup/parser/PositionTest.java
index 49d544c5..e8098095 100644
--- a/src/test/java/org/jsoup/parser/PositionTest.java
+++ b/src/test/java/org/jsoup/parser/PositionTest.java
@@ -487,6 +487,15 @@ class PositionTest {
         assertEquals("h1:0-9~12-17; id:4-6=7-8; #text:9-12; #text:17-18; h2:18-27~30-35; id:22-24=25-26; #text:27-30; h10:35-40~43-49; #text:40-43; ", track.toString());
     }
 
+    @Test void tracksAfterPSelfClose() {
+        // https://github.com/jhy/jsoup/issues/2175
+        String html = "foo<p/>bar &amp; 2";
+        Document doc = Jsoup.parse(html, TrackingHtmlParser);
+        StringBuilder track = new StringBuilder();
+        doc.body().forEachNode(node -> accumulatePositions(node, track));
+        assertEquals("body:0-0~18-18; #text:0-3; p:3-7~3-7; #text:7-18; ", track.toString());
+    }
+
     @Test void tracksFirstTextnode() {
         // https://github.com/jhy/jsoup/issues/2106
         String html = "foo<p></p>bar<p></p><div><b>baz</b></div>";