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

Cannot use selectors containing attribute #262

Closed
Pirikara opened this issue Apr 28, 2022 · 3 comments
Closed

Cannot use selectors containing attribute #262

Pirikara opened this issue Apr 28, 2022 · 3 comments
Assignees
Labels

Comments

@Pirikara
Copy link

An invalid selector string containing attribute is created for the following elements.

// MyElement
<input type="checkbox" value="9659985">

The effect of CSS.escape() will return the following string for elements where value is a number.
It cannot be queried with document.querySelector and returns null.

getCssSelector(MyElement)
// => [value=''\\39 659985''] 

I can make the PR if your want to.

Regards

@fczbkk fczbkk self-assigned this Apr 29, 2022
@fczbkk fczbkk added the bug label Apr 29, 2022
@fczbkk
Copy link
Owner

fczbkk commented Apr 29, 2022

Nice catch @yamashita-tutorial-tomoya.

According to specification, attribute selector value has to be ident-token. That means it can not start with a number.
https://drafts.csswg.org/css-syntax-3/#typedef-ident-token

I'd say that the value of an <input /> element should not be used in attribute selector. And I think same should go for <option />. I will add a condition that will reject them as candidates.

@fczbkk fczbkk closed this as completed in f9eece2 Apr 29, 2022
@fczbkk
Copy link
Owner

fczbkk commented Apr 29, 2022

Released v3.6.1 which should fix this issue.
https://www.npmjs.com/package/css-selector-generator/v/3.6.1

@fregante
Copy link
Contributor

fregante commented Jun 9, 2022

I don’t think this is the correct fix, [value="9659985"] works. I think CSS.escape should not be run on attribute selectors, I think you only need to escape the specific quote you're using to wrap the value.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants