-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Closed
Labels
bugA confirmed bug, that we should fixA confirmed bug, that we should fix
Milestone
Description
Hello,
import org.jsoup.nodes.*;
import org.jsoup.parser.*;
import org.jsoup.select.*;
public class Test {
public static void main(String[] args) {
HtmlTreeBuilder treeBuilder = new HtmlTreeBuilder();
Parser parser = new Parser(treeBuilder);
parser.setTrackPosition(true);
Document document = parser.parseInput("foo<p></p>bar<p></p><div><b>baz</b></div>", "");
NodeTraversor.traverse((Node node, int depth) -> {
if (node instanceof TextNode textNode) {
Range sourceRange = textNode.sourceRange();
System.out.printf("text=%s start=%d end=%d%n",
textNode.text(),
sourceRange.start().pos(),
sourceRange.end().pos());
}
}, document);
}
}
We seeing -ve start/end positions for the source range of the first text node foo
, for example using release 1.16.1
:
java -cp ~/.m2/repository/org/jsoup/jsoup/1.16.1/jsoup-1.16.1.jar Test.java
text=foo start=-1 end=-1
text=bar start=10 end=13
text=baz start=28 end=31
Release 1.17.2
has the end position correct, but the start is still -1
java -cp ~/.m2/repository/org/jsoup/jsoup/1.17.2/jsoup-1.17.2.jar Test.java
text=foo start=-1 end=3
text=bar start=10 end=13
text=baz start=28 end=31
Metadata
Metadata
Assignees
Labels
bugA confirmed bug, that we should fixA confirmed bug, that we should fix