Skip to content

case insensitive matching #517

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

Merged
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
1 change: 1 addition & 0 deletions plugins/css-blank-pseudo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
more efficient and also does less work at the MutationObserver handler.
- Breaking: removed old CDN urls
- Breaking: removed old CLI
- Fix case insensitive matching.

#### How to migrate:

Expand Down
12 changes: 5 additions & 7 deletions plugins/css-blank-pseudo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
return {
postcssPlugin: 'css-blank-pseudo',
Rule: (rule, { result }) => {
if (rule.selector.indexOf(':blank') === -1) {
if (rule.selector.toLowerCase().indexOf(':blank') === -1) {
return;
}

let modifiedSelector;
try {
const modifiedSelectorAST = parser((selectors) => {
selectors.walkPseudos((selector) => {
if (selector.value !== ':blank') {
if (selector.value.toLowerCase() !== ':blank') {
return;
}

Expand All @@ -66,12 +66,10 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
return;
}

const clone = rule.clone({ selector: modifiedSelector });
rule.cloneBefore({ selector: modifiedSelector });

if (options.preserve) {
rule.before(clone);
} else {
rule.replaceWith(clone);
if (!options.preserve) {
rule.remove();
}
},
};
Expand Down
4 changes: 4 additions & 0 deletions plugins/css-blank-pseudo/test/basic.css
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ test :matches(test :blank :blank test) test {
test:not(:blank) {
order: 5;
}

uppercase :BLaNK {
order: 6;
}
8 changes: 8 additions & 0 deletions plugins/css-blank-pseudo/test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ test:not([blank]) {
test:not(:blank) {
order: 5;
}

uppercase [blank] {
order: 6;
}

uppercase :BLaNK {
order: 6;
}
4 changes: 4 additions & 0 deletions plugins/css-blank-pseudo/test/basic.preserve.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,7 @@ test :matches(test [blank] [blank] test) test {
test:not([blank]) {
order: 5;
}

uppercase [blank] {
order: 6;
}
8 changes: 8 additions & 0 deletions plugins/css-blank-pseudo/test/basic.replacewith.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,11 @@ test:not(.css-blank) {
test:not(:blank) {
order: 5;
}

uppercase .css-blank {
order: 6;
}

uppercase :BLaNK {
order: 6;
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ test :matches(test :blank :blank test) test {
test:not(:blank) {
order: 5;
}

uppercase :BLaNK {
order: 6;
}
1 change: 1 addition & 0 deletions plugins/css-has-pseudo/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
- Added: 'forcePolyfill' options for browser polyfill
- Added: Rules within `@supports selector(:has(something))` won't be transformed.
- Fix: Use base36 encoding to support all possible selectors.
- Fix: case insensitive matching.

#### How to migrate :

Expand Down
10 changes: 5 additions & 5 deletions plugins/css-has-pseudo/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const creator: PluginCreator<{ preserve?: boolean, specificityMatchingName?: str
return {
postcssPlugin: 'css-has-pseudo-experimental',
RuleExit: (rule, { result }) => {
if (!rule.selector.includes(':has(') || isWithinSupportCheck(rule)) {
if (!rule.selector.toLowerCase().includes(':has(') || isWithinSupportCheck(rule)) {
return;
}

const selectors = rule.selectors.map((selector) => {
if (!selector.includes(':has(')) {
if (!selector.toLowerCase().includes(':has(')) {
return selector;
}

Expand All @@ -41,7 +41,7 @@ const creator: PluginCreator<{ preserve?: boolean, specificityMatchingName?: str

let containsHasPseudo = false;
selectorAST.walkPseudos((node) => {
containsHasPseudo = containsHasPseudo || (node.value === ':has' && node.nodes);
containsHasPseudo = containsHasPseudo || (node.value.toLowerCase() === ':has' && node.nodes);

// see : https://bugs.chromium.org/p/chromium/issues/detail?id=669058#c34
// When we have ':has(:visited) {...}', the subject elements of the rule
Expand All @@ -51,15 +51,15 @@ const creator: PluginCreator<{ preserve?: boolean, specificityMatchingName?: str
// selector does not match if it is inside the ':has()' argument selector.
// So if a ':has()' argument selector requires a matching ':visited', the
// style rule are not applied.
if (node.value === ':visited') {
if (node.value.toLowerCase() === ':visited') {
// We can't leave `:has` untouched as that might cause broken selector lists.
// Replacing with the specificity matching name as this should never match anything without `:not()`.
node.replaceWith(parser.className({
value: options.specificityMatchingName,
}));
}

if (node.value === ':any-link') {
if (node.value.toLowerCase() === ':any-link') {
// we can transform `:any-link` to `:link` as this is allowed
node.value = ':link';
}
Expand Down
8 changes: 4 additions & 4 deletions plugins/css-has-pseudo/src/is-guarded-by-at-supports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import valueParser from 'postcss-value-parser';
import selectorParser from 'postcss-selector-parser';

export function isGuardedByAtSupportsFromAtRuleParams(atSupportsParams: string): boolean {
if (!atSupportsParams.includes(':has(')) {
if (!atSupportsParams.toLowerCase().includes(':has(')) {
return false;
}

Expand All @@ -13,7 +13,7 @@ export function isGuardedByAtSupportsFromAtRuleParams(atSupportsParams: string):

const ast = valueParser(atSupportsParams);
ast.walk((node) => {
if (node.type === 'function' && node.value === 'selector') {
if (node.type === 'function' && node.value.toLowerCase() === 'selector') {
selectors.add(valueParser.stringify(node.nodes));
return false;
}
Expand All @@ -33,7 +33,7 @@ export function isGuardedByAtSupportsFromAtRuleParams(atSupportsParams: string):
}

export function selectorContainsHasPseudo(selector: string): boolean {
if (!selector.includes(':has(')) {
if (!selector.toLowerCase().includes(':has(')) {
return false;
}

Expand All @@ -42,7 +42,7 @@ export function selectorContainsHasPseudo(selector: string): boolean {
try {
const ast = selectorParser().astSync(selector);
ast.walk((node) => {
if (node.type === 'pseudo' && node.value === ':has' && node.nodes && node.nodes.length > 0) {
if (node.type === 'pseudo' && node.value.toLowerCase() === ':has' && node.nodes && node.nodes.length > 0) {
containsHasPseudo = true;
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/css-has-pseudo/test/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
color: grey
}

#d_main:has(#d_checkbox:checked)>#d_subject {
#d_main:HAS(#d_checkbox:checked)>#d_subject {
color: red
}

#d_main:has(#d_option:checked)>#d_subject {
color: red
}

#d_main:has(#d_checkbox:disabled)>#d_subject {
#d_main:hAs(#d_checkbox:disabled)>#d_subject {
color: green
}

Expand Down
4 changes: 2 additions & 2 deletions plugins/css-has-pseudo/test/browser.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
color: grey
}

[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-2p-37-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2r-2w-2t-2r-2z-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
[csstools-has-z-2s-2n-31-2p-2x-32-1m-20-1t-2b-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2r-2w-2t-2r-2z-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
color: red
}

[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-2p-37-14-z-2s-2n-33-34-38-2x-33-32-1m-2r-2w-2t-2r-2z-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
color: red
}

[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-2p-37-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2s-2x-37-2p-2q-30-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
[csstools-has-z-2s-2n-31-2p-2x-32-1m-2w-1t-37-14-z-2s-2n-2r-2w-2t-2r-2z-2q-33-3c-1m-2s-2x-37-2p-2q-30-2t-2s-15-1q-z-2s-2n-37-39-2q-2y-2t-2r-38]:not(#does-not-exist):not(#does-not-exist):not(#does-not-exist) {
color: green
}

Expand Down
1 change: 1 addition & 0 deletions plugins/css-prefers-color-scheme/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
- Breaking: remove `color-depth` queries fallback
- Breaking: remove 'no-preference' support as this was dropped from the spec
- Breaking: remove old global object
- Fix: case insensitive matching.

#### How to migrate :

Expand Down
2 changes: 1 addition & 1 deletion plugins/css-prefers-color-scheme/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const creator: PluginCreator<pluginOptions> = (opts?: pluginOptions) => {
return {
postcssPlugin: 'postcss-prefers-color-scheme',
AtRule: (atRule) => {
if (atRule.name !== 'media') {
if (atRule.name.toLowerCase() !== 'media') {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion plugins/css-prefers-color-scheme/test/browser.css
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
}
}

@media (prefers-color-scheme: light) {
@MEDIA (PREFERS-COLOR-SCHEME: LIGHT) {
#fixture {
color: rgb(255, 192, 203);
}
Expand Down
4 changes: 2 additions & 2 deletions plugins/css-prefers-color-scheme/test/browser.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
}
}

@media (color: 70318723) {
@MEDIA (color: 70318723) {
#fixture {
color: rgb(255, 192, 203);
}
}

@media (prefers-color-scheme: light) {
@MEDIA (PREFERS-COLOR-SCHEME: LIGHT) {
#fixture {
color: rgb(255, 192, 203);
}
Expand Down