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

Conversation

YairRand
Copy link
Contributor

Change lookAheadNotOpenBracePattern to allow selectors to match "" patterns (eg [class="span"]) and selectors with comments interspersed. This fixes issue #35, where text before either comments or attribute selectors using double quotes were not being considered part of the selector, and having text flipped as though they were part of rules. (Eg .right [class="span"] { float: right; } was flipped to .left .)

Change lookAheadNotOpenBracePattern to allow selectors to match "" patterns (eg [class="span"]) and selectors with comments interspersed. This fixes issue wikimedia#35, where text before either comments or attribute selectors using double quotes were not being considered part of the selector, and having text flipped as though they were part of rules. (Eg `.right [class="span"] { float: right; }` was flipped to `.left` .)
@Krinkle Krinkle self-assigned this Feb 11, 2018
@Krinkle
Copy link
Member

Krinkle commented Feb 11, 2018

Thanks!

Add tests for "leave class names alone" to work when selector includes either comments or attribute selectors with double quotes.
@@ -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.)

@Krinkle
Copy link
Member

Krinkle commented Aug 23, 2020

Benchmark

Before:

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3229 op/s in 0.3s
Bench ooui: 645 op/s in 1.5s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3176 op/s in 0.3s
Bench ooui: 636 op/s in 1.6s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3198 op/s in 0.3s
Bench ooui: 637 op/s in 1.6s

After:

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3140 op/s in 0.3s
Bench ooui: 630 op/s in 1.6s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3197 op/s in 0.3s
Bench ooui: 644 op/s in 1.6s

nobody@0c6fcfefbc0c:/cssjanus$ node test/bench.js 
Bench mediawiki: 3243 op/s in 0.3s
Bench ooui: 644 op/s in 1.6s

@Krinkle Krinkle closed this in b9aac27 Aug 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants