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

"* html" incorrectly matches elements #8

Closed
SLaks opened this issue Nov 27, 2012 · 10 comments
Closed

"* html" incorrectly matches elements #8

SLaks opened this issue Nov 27, 2012 · 10 comments

Comments

@SLaks
Copy link

SLaks commented Nov 27, 2012

(tested using Cheerio & htmlparser2)

The selector * html will incorrectly match the <html> element, because it picks up the virtual type: 'root' element as a parent.
* * html will correctly not match anything.

@SLaks
Copy link
Author

SLaks commented Nov 27, 2012

I think the fix would be to change universal to return a function that checks that elem.type !== 'root'.

However, I'm not sure.

@fb55
Copy link
Owner

fb55 commented Nov 27, 2012

This is actually a cheerio issue, as the default DOM returned by my DomHandler module has no elements of the type root.

:root shouldn't work with cheerio, either.

@matthewmueller Does cheerio need the root element?

@SLaks
Copy link
Author

SLaks commented Nov 27, 2012

I was wondering about that...

@matthewmueller
Copy link

Having a root simplifies a lot of the top-level logic and allows you to append and prepend on single DOM Nodes.

var plum = '<li class="plum">Plum</li>',
     apple = '<li class="apple">Apple</li>',
     $ = cheerio.load(plum);

$.root().append(apple)
$.html() // <li class="plum">Plum</li><li class="apple">Apple</li>

This isn't often necessary in the jquery work because you're not adding things to <html>, but it turns out to be useful when you're doing HTML manipulations with fragments.

@SLaks
Copy link
Author

SLaks commented Nov 27, 2012

Any idea what the best way to work around this issue is?

CSSselect could have special-case code for Cheerio's type="root" element

@matthewmueller
Copy link

what's your use case for matching $('* html') ? that seems a bit bizarre to me

@SLaks
Copy link
Author

SLaks commented Nov 27, 2012

I'm trying to make the Acid2 test pass in my server-side HTML mangler.

@matthewmueller
Copy link

Did you try the other equivalents: $('*').find('html'), $('html', '*')?

@SLaks
Copy link
Author

SLaks commented Nov 27, 2012

I'm running Cheerio on all of the CSS selectors in the test, and this selector is incorrectly matching elements.

@fb55
Copy link
Owner

fb55 commented Feb 15, 2013

This won't be fixed in CSSselect. I opened a cheerio issue (cheeriojs/cheerio#162), everything else should be discussed there.

@fb55 fb55 closed this as completed Feb 15, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants