Use case-insensitive compares on domain. Fixes #598
This commit is contained in:
parent
9fe721945d
commit
cc30b39fae
|
@ -1,6 +1,6 @@
|
||||||
/* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */
|
/* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */
|
||||||
/* global createCache db calcStyleDigest db tryRegExp styleCodeEmpty
|
/* global createCache db calcStyleDigest db tryRegExp styleCodeEmpty
|
||||||
getStyleWithNoCode msg */
|
getStyleWithNoCode msg domainInsensitive */
|
||||||
/* exported styleManager */
|
/* exported styleManager */
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
@ -418,21 +418,26 @@ const styleManager = (() => {
|
||||||
}
|
}
|
||||||
|
|
||||||
function urlMatchSection(url, section) {
|
function urlMatchSection(url, section) {
|
||||||
|
url = domainInsensitive(url);
|
||||||
const domain = getDomain(url);
|
const domain = getDomain(url);
|
||||||
if (section.domains && section.domains.some(d => d === domain || domain.endsWith(`.${d}`))) {
|
if (
|
||||||
|
section.domains &&
|
||||||
|
section.domains.some(d => domainInsensitive(d) === domain || domain.endsWith(`.${d}`))
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (section.urlPrefixes && section.urlPrefixes.some(p => url.startsWith(p))) {
|
if (
|
||||||
|
section.urlPrefixes &&
|
||||||
|
section.urlPrefixes.some(p => domainInsensitive(url).startsWith(domainInsensitive(p)))
|
||||||
|
) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
// as per spec the fragment portion is ignored in @-moz-document:
|
// as per spec the fragment portion is ignored in @-moz-document:
|
||||||
// https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#url-of-doc
|
// https://www.w3.org/TR/2012/WD-css3-conditional-20120911/#url-of-doc
|
||||||
// but the spec is outdated and doesn't account for SPA sites
|
// but the spec is outdated and doesn't account for SPA sites
|
||||||
// so we only respect it for `url()` function
|
// so we only respect it for `url()` function
|
||||||
if (section.urls && (
|
const urls = section.urls && section.urls.map(domainInsensitive);
|
||||||
section.urls.includes(url) ||
|
if (urls && (urls.includes(url) || urls.includes(getUrlNoHash(url)))) {
|
||||||
section.urls.includes(getUrlNoHash(url))
|
|
||||||
)) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (section.regexps && section.regexps.some(r => compileRe(r).test(url))) {
|
if (section.regexps && section.regexps.some(r => compileRe(r).test(url))) {
|
||||||
|
|
|
@ -69,11 +69,18 @@ function styleSectionsEqual(a, b, {ignoreCode, checkSource} = {}) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function domainInsensitive(url) {
|
||||||
|
const parts = url.split('/');
|
||||||
|
const domainIndex = url.indexOf('://') < 0 ? 0 : 2;
|
||||||
|
parts[domainIndex] = parts[domainIndex].toLowerCase();
|
||||||
|
return parts.join('/');
|
||||||
|
}
|
||||||
|
|
||||||
function normalizeStyleSections({sections}) {
|
function normalizeStyleSections({sections}) {
|
||||||
// retain known properties in an arbitrarily predefined order
|
// retain known properties in an arbitrarily predefined order
|
||||||
return (sections || []).map(section => ({
|
return (sections || []).map(section => ({
|
||||||
code: section.code || '',
|
code: section.code || '',
|
||||||
urls: section.urls || [],
|
urls: (section.urls || []).map(domainInsensitive),
|
||||||
urlPrefixes: section.urlPrefixes || [],
|
urlPrefixes: section.urlPrefixes || [],
|
||||||
domains: section.domains || [],
|
domains: section.domains || [],
|
||||||
regexps: section.regexps || [],
|
regexps: section.regexps || [],
|
||||||
|
|
Loading…
Reference in New Issue
Block a user