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

list-sequences doesn’t handle all attribute selectors #105

Open
ghost opened this issue Feb 7, 2017 · 2 comments
Open

list-sequences doesn’t handle all attribute selectors #105

ghost opened this issue Feb 7, 2017 · 2 comments

Comments

@ghost
Copy link

ghost commented Feb 7, 2017

I have selectors that look like this:

.component-name > [data-size~="s:2"] {}

and this:

.component-name > [data-size="s:2"] {}

I would expect the second parts of those selectors to be matched by this:

^(?:\\[.+\\])$

However, since the list-sequences function

  1. splits the string on :
  2. splits the result of (1) on /[\s>+~]/

what gets matched against my regex is either

[data-size

or

[data-size="s

So I’m thinking the splitting needs to avoid matching characters inside attribute selectors.

@davidtheclark
Copy link
Contributor

@rgrjoh Good point! If you'd like to contribute a fix, I suggest using https://github.com/postcss/postcss-selector-parser.

@ghost
Copy link
Author

ghost commented Feb 7, 2017

I don’t have time to read up on postcss-selector-parser right now, but I tested a quick hack (which can still go wrong, but should at least handle more situations than the current implementation):

module.exports = function(selector) {
  var withoutPseudos = selector.split(/:+(before|after|link|visited|hover|focus|active)/)[0]; /* Add all possible pseudo-selectors */
  return withoutPseudos
    .split(/[\s>+]|~(?!=)/)
    .filter(function(s) {
      return s !== '';
    });
}

Both splits will incorrectly match the content of attribute selectors, eg. [data-whatever="foo:before"] or [data-whatever="a>b"].

But the best solution would be to do what you suggest and use a parsing library.

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

1 participant