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

find() selector that starts with double hyphen gives "Failed to parse selector" error #1339

Closed
TimTouchtribe opened this issue Nov 9, 2017 · 14 comments

Comments

@TimTouchtribe
Copy link

I've tried to find an element with class --left in it with element.find('a.--left').
This however gives the error Error: Failed to parse selector: a.--left
When I remove the double hyphen in the component and the selector it does work.

@ljharb
Copy link
Member

ljharb commented Nov 9, 2017

That seems like it’s because you can’t have a class name that starts with a hyphen - iow, it’s actually an invalid selector.

@TimTouchtribe
Copy link
Author

Okay, you're right, my bad :)
Although I did come up with a solution: \--left
This however gives me the same error: Error: Failed to parse selector: a.\--left
according to https://jigsaw.w3.org/css-validator/validator this is valid CSS3, so the selector should work right? I did escape it in the find so it looks like this: element.find('a.\\--left')
Any idea why this doesn't work?
Thanks for your help so far :)

@ljharb
Copy link
Member

ljharb commented Nov 13, 2017

I’m not sure about that validator, but the spec says it’s not valid: http:https://www.w3.org/TR/CSS21/syndata.html#characters

@ljharb
Copy link
Member

ljharb commented Nov 13, 2017

(That link is for v2.1 but i don’t think it changed in css3)

@aweary
Copy link
Collaborator

aweary commented Nov 13, 2017

document.querySelector('.--foo') seems to work in Chrome. I'm not exactly sure if its spec compliant (I'm assuming Chrome is), but we could look into allowing leading hyphens.

As for escaped characters, we're aware its an issue and we do want to support it. See #1218.

@ljharb ljharb added this to Open in Make string selectors awesome via automation Nov 13, 2017
@TimTouchtribe
Copy link
Author

my apologies for the wrong link, I did not test to see if it works.
Hereby the link to the actual css validator, which proofs that \--left is correct css3.
https://jigsaw.w3.org/css-validator/#validate_by_input

@aweary
Copy link
Collaborator

aweary commented Nov 29, 2017

This will be resolved by aweary/rst-selector-parser#11

@tyger
Copy link

tyger commented Dec 1, 2017

The reality is that '--' prefix for class names is quite often used for BEM styled naming of modifiers (no namespace notation).

Make string selectors awesome automation moved this from Open to Closed/Merged Feb 21, 2018
@kamranayub
Copy link

kamranayub commented May 4, 2018

@aweary

Alright, I ran into this today but according to this issue and PRs it's fixed. I'm using [email protected] which should be using [email protected].

I'm getting this error when I try the following variations:

wrapper.find(".--active");
wrapper.find(".\\--active");

Neither seem to work, I get the Failed to parse selector error.

@ljharb
Copy link
Member

ljharb commented Jun 26, 2018

@kamranayub you may need to rm -rf node_modules && npm install to get the update.

@opr
Copy link

opr commented Sep 18, 2018

Using enzyme 3.6.0 I'm getting the Failed to parse selector: div.hero-slide.\--initialised error
This is how I produce the error:

const divsWithInitialised = heroSlider(props).find('div.hero-slide.\\--initialised');

@ljharb
Copy link
Member

ljharb commented Sep 18, 2018

What version of rst-selector-parser do you have? If it’s the latest, then please file a new issue.

@cmmash
Copy link

cmmash commented Feb 27, 2019

Guys would the square brackets in a className be valid? Example:
_test-field-secondaryConditions[0].sourceValue

@ljharb
Copy link
Member

ljharb commented Feb 27, 2019

What does document.querySelector do with those?

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

No branches or pull requests

7 participants