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

Whitespace around operator breaks nth-child selectors #20

Closed
jkillian opened this issue Aug 17, 2018 · 3 comments
Closed

Whitespace around operator breaks nth-child selectors #20

jkillian opened this issue Aug 17, 2018 · 3 comments

Comments

@jkillian
Copy link

jkillian commented Aug 17, 2018

Given this html page:

<!DOCTYPE html>
<script type="text/javascript" src="src/nwsapi.js"></script>
<div>
  <p>first</p>
  <p>second</p>
  <p>third</p>
</div>

The selector p:nth-child(2n + 1) only works if SIMPLENOT is false:

image

The same selector without whitespace, p:nth-child(2n+1), works in both modes. The spec allows whitespace, so ideally both selectors should always work.

In addition, prettier seems to autoformat CSS selectors with spaces in this situation. So this bug leads to a sad case where autoformatting your code with prettier can cause unit tests to break in the Jest -> JSDOM -> NWSAPI stack (or anything else relying on JSDOM to run tests).

Thanks for the help!

Edit: I believe the issue goes beyond SIMPLE_NOT, for example, p:nth-child(2n - 1) doesn't work in either mode.

@dperini
Copy link
Owner

dperini commented Aug 18, 2018

That seems easy to fix, I will have a look asap.

Probably these are the consequence of applying the following commit (security fix):
acaa23b

Are you using latest version (2.0.8) ?

@jkillian
Copy link
Author

Thanks for the quick response! Yes, I reproduced the issue on the latest version, see the test cases in my PR here: #21 (I'm not sure if my fix is the correct fix, but it does demonstrate the issue)

I think if we're concerned about using \s*, \s? would suffice - allowing one space character would fix the issue with regards to CSS autoformatting.

@jkillian jkillian changed the title Config.SIMPLE_NOT breaks some unrelated selectors Whitespace around operator breaks nth-child selectors Aug 18, 2018
dperini added a commit that referenced this issue Sep 1, 2018
@jkillian
Copy link
Author

Thanks for the fix in 9dfcc2a @dperini! I'm going to close this issue out as it's resolved now.

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

Successfully merging a pull request may close this issue.

2 participants