question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support escaped characters in selectors

See original GitHub issue

Edit from maintainers: this issue was repurposed, see https://github.com/airbnb/enzyme/issues/1218#issuecomment-334489966

Settings

  • React v16
  • Enzyme v3

When i have a component which has a className prop with special character / or @ , it doesnt select anything. I feel enzyme breaks and doesn’t continue with the lines after this selector.

Example

const sampleComponent = () => (
    <div className="u-width-1/2@small">
        Something here
    </div>
);

If I have the above component and if I want to select the div containing u-width-1/2@small I tried

const component = shallow(<sampleComponent />);
component.find('.u-width-1/2@small') // This line seems to fail due to error in selector
/* Anything after this doesnt execute */

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:14 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
ljharbcommented, Oct 3, 2017

That’s not a valid class name - that won’t work in the browser either.

6reactions
aaronthomascommented, Oct 5, 2017

I agree with @yash0087 and @coderas, a class with an @ symbol (or anything other than whitespace for that matter) is indeed a valid class name.

It’s worth noting the class names are defined by the HTML spec rather than CSS – though the CSS spec defines what is a valid class selector as per @yash0087’s link above. The HTML5 spec clearly states that classes are simply “a set of space-separated tokens”, which have no restrictions other than whitespace characters: https://www.w3.org/TR/2011/WD-html5-20110525/elements.html#classes

In addition, the argument that document.querySelector does not allow those characters is also false. document.querySelector uses the Selectors API, which explicitly states that the same escaping rules as CSS should be applied for special characters: https://drafts.csswg.org/selectors-4/#case-sensitive.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSS.escape() - Web APIs - MDN Web Docs
The CSS.escape() static method returns a string containing the escaped string passed as parameter, mostly for use as part of a CSS selector....
Read more >
CSS character escape sequences - Mathias Bynens
Here's a simple list of rules you should keep in mind when escaping a character in CSS. Keep in mind that if you're...
Read more >
Escaping characters in CSS class selectors - Stack Overflow
I'm trying to implement this W3 description of character escapes in CSS class selectors. I'm running into problems with the abc\20 def ...
Read more >
Using character escapes in markup and CSS - W3C
Using escapes with CSS identifiers ... Identifiers in CSS, such as class names in CSS selectors, can begin with - _ a-z or...
Read more >
Using special characters in selectors - ProcessWire
This might be a silly question but wire('sanitizer')->selectorValue() seems to remove characters like ^ and = rather than escape them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found