From cc30b39fae5198a65af9bb186444602517edf4c1 Mon Sep 17 00:00:00 2001 From: Rob Garrison Date: Sun, 2 Dec 2018 14:11:29 -0600 Subject: [PATCH] Use case-insensitive compares on domain. Fixes #598 --- background/style-manager.js | 19 ++++++++++++------- js/sections-util.js | 9 ++++++++- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index 25f649b8..60edbb56 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -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))) { diff --git a/js/sections-util.js b/js/sections-util.js index aeeeb19b..bb654b8c 100644 --- a/js/sections-util.js +++ b/js/sections-util.js @@ -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 || [],