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

Pseudo-classes, pseudo-elements, attributes are given incorrect specificity #13

Open
csnover opened this issue Jan 28, 2013 · 2 comments

Comments

@csnover
Copy link

csnover commented Jan 28, 2013

getScoreForSelector treats pseudo-classes like pseudo-elements, but they actually have the same specificity as a regular class. It also does not handle :not() correctly, and it does not handle attribute selectors at all. The diff below is not perfect but it improves the situation:

diff --git a/inlinestyle/inlinestyle/InlineStyle/InlineStyle.php b/inlinestyle/inlinestyle/InlineStyle/InlineStyle.php
index 4e22a29..74f1927 100644
--- a/protected/vendors/composer/inlinestyle/inlinestyle/InlineStyle/InlineStyle.php
+++ b/protected/vendors/composer/inlinestyle/inlinestyle/InlineStyle/InlineStyle.php
@@ -270,9 +270,9 @@ class InlineStyle
     public function getScoreForSelector($selector)
     {
         return array(
-            preg_match_all('/#\w/i', $selector, $result), // ID's
-            preg_match_all('/\.\w/i', $selector, $result), // Classes
-            preg_match_all('/^\w|\ \w|\(\w|\:[^not]/i', $selector, $result) // Tags
+            preg_match_all('/#\w/i', $selector, $result), // IDs
+            preg_match_all('/\.\w|\[|(?<!:):(?!not\(|before|after|:)/i', $selector, $result), // Classes, attributes, and pseudo-classes
+            preg_match_all('/^\w|\ \w|\(\w|:(?::|before|after)/i', $selector, $result) // Tags and pseudo-elements
         );
     }
@christiaan
Copy link
Owner

Maybe you can create some tests instead. See the testGetScoreForSelector method in the InlineStyleTest class.
Then we can see if we can get those tests to pass.

@csnover
Copy link
Author

csnover commented Jan 30, 2013

I would like to. This is absolutely the worst excuse in the world, but I don’t have any real time to devote to this, so I am at least trying to get these things down for now and maybe I will be able to follow up in a couple…years. I did a quick search and did not find an existing specificity test suite, though that does not mean one does not exist.

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

2 participants