From 03b1c9abecb7a9869bc79394ccdaefda0cea3aaf Mon Sep 17 00:00:00 2001 From: eight Date: Thu, 28 Mar 2019 13:57:06 +0800 Subject: [PATCH] Breaking: make exclusion rules work like match pattern --- background/style-manager.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/background/style-manager.js b/background/style-manager.js index f0601573..d75d7b3f 100644 --- a/background/style-manager.js +++ b/background/style-manager.js @@ -43,7 +43,7 @@ const styleManager = (() => { const BAD_MATCHER = {test: () => false}; const compileRe = createCompiler(text => `^(${text})$`); const compileSloppyRe = createCompiler(text => `^${text}$`); - const compileExclusion = createCompiler(buildGlob); + const compileExclusion = createCompiler(buildExclusion); const DUMMY_URL = { hash: '', @@ -544,8 +544,22 @@ const styleManager = (() => { }; } - function buildGlob(text) { - return '^' + escapeRegExp(text).replace(/\\\\\\\*|\\\*/g, m => m.length > 2 ? m : '.*') + '$'; + function compileGlob(text) { + return escapeRegExp(text).replace(/\\\\\\\*|\\\*/g, m => m.length > 2 ? m : '.*'); + } + + function buildExclusion(text) { + // match pattern + const match = text.match(/^(\*|[\w-]+):\/\/(\*\.)?([\w.]+\/.*)/); + if (!match) { + return '^' + compileGlob(text) + '$'; + } + return '^' + + (match[1] === '*' ? '[\\w-]+' : match[1]) + + '://' + + (match[2] ? '(?:[\\w.]+\\.)?' : '') + + compileGlob(match[3]) + + '$'; } // The md5Url provided by USO includes a duplicate "update" subdomain (see #523),