Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Element.cssSelector stop returning value #root after upgrading to 1.17 from 1.14 #2082

Open
smileLilith opened this issue Dec 14, 2023 · 3 comments
Labels
needs-more-info More information is needed from the reporter to progress the issue

Comments

@smileLilith
Copy link

Hi team,

After upgrading from v1.14.3 to 1.17.1 I ran into an issue where Element.cssSelector stopped returning value #root for element with tag name #root. I have found nothing relevant in the release notes indicating the change of behavior.

Example

Document doc = Jsoup.parse("<p>hello</p>");
System.out.println(doc.cssSelector());

Output v1.14.3

#root

Output v1.17.1

(empty string)
@smileLilith smileLilith changed the title Element.cssSelector stop returning value #root after upgrading to 1.17 from 1.14 Element.cssSelector stop returning value #root after upgrading to 1.17 from 1.14 Dec 14, 2023
@smileLilith
Copy link
Author

smileLilith commented Dec 14, 2023

It seems the behavior was broken in this commit 9170b1d where cssSelectorComponent isn't executed for element of instance Document where previously it was.

cssSelectorComponent contains the line

if (parent() == null || parent() instanceof Document) // don't add Document to selector, as will always have a html node
, however, it's not reachable due to
while (el != null && !(el instanceof Document)) {

@jhy was there any reason behind that?

@jhy
Copy link
Owner

jhy commented Dec 14, 2023

@jhy was there any reason behind that?

Yes, as noted in the comment if you're getting a selector for an element it is going to descend from html and so it doesn't need the #root selector. And the #root nodename is not really documented, or supported outside of jsoup. I felt it was wrong to be leaking in to the selector.

Can you tell me more about your use case - what do need a Document selector generated from a Document for?

Perhaps we could change the cssSelector method to return #root if it's called on a Document directly, or there's no other contents to the selector.

@jhy
Copy link
Owner

jhy commented Dec 30, 2023

Also - returning #root is just wrong as it won't match anything - it would look for elements with an ID of root, which won't match.

So I'm confused that you're hitting an issue here; would be great to get some more details.

@jhy jhy added the needs-more-info More information is needed from the reporter to progress the issue label Dec 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-more-info More information is needed from the reporter to progress the issue
Projects
None yet
Development

No branches or pull requests

2 participants