Use case-insensitive compares on domain. Fixes #598

This commit is contained in:
Rob Garrison 2018-12-02 14:11:29 -06:00
parent 9fe721945d
commit cc30b39fae
2 changed files with 20 additions and 8 deletions

View File

@ -1,6 +1,6 @@
/* eslint no-eq-null: 0, eqeqeq: [2, "smart"] */
/* global createCache db calcStyleDigest db tryRegExp styleCodeEmpty
getStyleWithNoCode msg */
getStyleWithNoCode msg domainInsensitive */
/* exported styleManager */
'use strict';
@ -418,21 +418,26 @@ const styleManager = (() => {
}
function urlMatchSection(url, section) {
url = domainInsensitive(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;
}
if (section.urlPrefixes && section.urlPrefixes.some(p => url.startsWith(p))) {
if (
section.urlPrefixes &&
section.urlPrefixes.some(p => domainInsensitive(url).startsWith(domainInsensitive(p)))
) {
return true;
}
// as per spec the fragment portion is ignored in @-moz-document:
// 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
// so we only respect it for `url()` function
if (section.urls && (
section.urls.includes(url) ||
section.urls.includes(getUrlNoHash(url))
)) {
const urls = section.urls && section.urls.map(domainInsensitive);
if (urls && (urls.includes(url) || urls.includes(getUrlNoHash(url)))) {
return true;
}
if (section.regexps && section.regexps.some(r => compileRe(r).test(url))) {

View File

@ -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}) {
// retain known properties in an arbitrarily predefined order
return (sections || []).map(section => ({
code: section.code || '',
urls: section.urls || [],
urls: (section.urls || []).map(domainInsensitive),
urlPrefixes: section.urlPrefixes || [],
domains: section.domains || [],
regexps: section.regexps || [],