From 2f8bd4ee34e2d67d74d00ce76d4c0b872f224eb9 Mon Sep 17 00:00:00 2001 From: Damien Churchill Date: Thu, 18 Jul 2019 11:09:38 +0100 Subject: [PATCH] Allow more control over the regular expression In some instances it would be good to be able to specify a regex as being case insensitive. This adds checking whether the urlRegex field is in the form of a Javascript regular expression before passing it to `.search()` and converts it if so. --- src/background.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/background.js b/src/background.js index 78a4762..4f82dc0 100644 --- a/src/background.js +++ b/src/background.js @@ -23,7 +23,8 @@ function passFilters_(url, type, filters) { switch (filter.type) { case 'urls': hasUrlFilters = true; - if (url.search(filter.urlRegex) == 0) { + let urlRegex = (filter.urlRegex.match('^/.*/[gim]*$')) ? RegExp(filter.urlRegex) : filter.urlRegex; + if (url.search(urlRegex) == 0) { allowUrls = true; } break;