You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Attribute#sourceRange return null when parse body attribute #2204
Hello
I want to parse my doc and read the attribute range, I had read the doc and the issue #1114. I found some time, the org.jsoup.nodes.Attribute#sourceRange return null. After test, I found if body tag is preceded by some tags, like p, span the org.jsoup.nodes.Attribute#sourceRange will return null,otherwise, it works normally. I don't know if this is a bug, is there some way to recognize it and get the range of attr?
my code:
import org.jsoup.nodes.Attribute;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.parser.Parser;
import java.io.FileInputStream;
public class TestMain {
public static void main(String[] args) throws Exception{
FileInputStream fis = new FileInputStream("tmp.html");
String text = new String(fis.readAllBytes());
Parser parser = org.jsoup.parser.Parser.htmlParser();
parser.setTrackPosition(true);
Document doc = Jsoup.parse(text,parser);
for (Element element : doc.getAllElements()){
Attribute targetAttr = element.attribute("target");
if (targetAttr != null){
System.out.println(targetAttr.sourceRange());
}
}
}
}
Activity
jhy commentedon Nov 22, 2024
Likely happening because the first
spancreates the actualbodyelement, and then we copy the secondbodys attributes over and miss the range.jhy commentedon Nov 22, 2024
Thanks for the clear report; fixed!
Copy attribute source range when merging attributes
chore(deps): update all non-major dependencies (mulk/mulkcms2!58)