Skip to content

Accept double-quotes, comments in selectors #53

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

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/cssjanus.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ function CSSJanus() {
colorPattern = '(#?' + nmcharPattern + '+|(?:rgba?|hsla?)\\([ \\d.,%-]+\\))',
urlCharsPattern = '(?:' + urlSpecialCharsPattern + '|' + nonAsciiPattern + '|' + escapePattern + ')*',
lookAheadNotLetterPattern = '(?![a-zA-Z])',
lookAheadNotOpenBracePattern = '(?!(' + nmcharPattern + '|\\r?\\n|\\s|#|\\:|\\.|\\,|\\+|>|\\(|\\)|\\[|\\]|=|\\*=|~=|\\^=|\'[^\']*\'])*?{)',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain the removal of the closing square bracket ] from the original line? Actually, I'm unsure as to why it what was there, but would be good to confirm whether its removal was important to this change, or just clean up, or something else.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't actually remember the reason for that, but I can guess.

Presumably, the original purpose of the ] was to ensure that the quotes were specifically part of simple attribute selector values, like [class='span'] ('] at the end), which are by far the most common use of quotes in selectors. However, this prevents it from matching other types of quotes in selectors, such as :lang("en") and [class='span' i]. (Currently, both have some browser support and are in Working Draft state of the spec.)

lookAheadNotOpenBracePattern = '(?!(' + nmcharPattern + '|\\r?\\n|\\s|#|\\:|\\.|\\,|\\+|>|\\(|\\)|\\[|\\]|=|\\*=|~=|\\^=|\'[^\']*\'|"[^"]*"|' + commentToken + ')*?{)',
lookAheadNotClosingParenPattern = '(?!' + urlCharsPattern + '?' + validAfterUriCharsPattern + '\\))',
lookAheadForClosingParenPattern = '(?=' + urlCharsPattern + '?' + validAfterUriCharsPattern + '\\))',
suffixPattern = '(\\s*(?:!important\\s*)?[;}])',
Expand Down
6 changes: 6 additions & 0 deletions test/data.json
Original file line number Diff line number Diff line change
Expand Up @@ -754,6 +754,12 @@
],
[
".a-foo.png { width: 0; }"
],
[
".foo-left /* comment */ { color: red; }"
],
[
"[class*=\"span\"].pull-right,.row-fluid [class*=\"span\"].pull-right { color: red; }"
]
]
},
Expand Down