From 73ac79feff76ecd71d5aeb15e05fc8486d5d8e3c Mon Sep 17 00:00:00 2001 From: gorhill Date: Fri, 22 May 2015 18:03:14 -0400 Subject: [PATCH] this fixes importing empty ABP custom ruleset --- src/_locales/en/messages.json | 4 ++-- src/js/1p-filters.js | 17 +++++++++++------ 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index c4fb03fd6..f26b32dd9 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -500,8 +500,8 @@ "description":"Firefox/Fennec-specific: Show Dashboard" }, "showNetworkLogButton":{ - "message":"Show Network Request Log", - "description":"Firefox/Fennec-specific: Show Network Request Log" + "message":"Show Logger", + "description":"Firefox/Fennec-specific: Show Logger" }, "fennecMenuItemBlockingOff": { "message": "off", diff --git a/src/js/1p-filters.js b/src/js/1p-filters.js index 442473fc3..c38bd7823 100644 --- a/src/js/1p-filters.js +++ b/src/js/1p-filters.js @@ -72,19 +72,24 @@ var handleImportFilePicker = function() { // https://github.com/chrisaljoudi/uBlock/issues/1004 // Support extraction of filters from ABP backup file var abpImporter = function(s) { - var reAbpExtractor = /\n\[Subscription\]\n+url=~[\x08-\x7E]+?\[Subscription filters\]([\x08-\x7E]*?)(?:\[Subscription\]|$)/ig; - var matches = reAbpExtractor.exec(s); + var reAbpSubscriptionExtractor = /\n\[Subscription\]\n+url=~[^\n]+([\x08-\x7E]*?)(?:\[Subscription\]|$)/ig; + var reAbpFilterExtractor = /\[Subscription filters\]([\x08-\x7E]*?)(?:\[Subscription\]|$)/i; + var matches = reAbpSubscriptionExtractor.exec(s); // Not an ABP backup file if ( matches === null ) { return s; } + // var out = []; + var filterMatch; while ( matches !== null ) { - if ( matches.length !== 2 ) { - continue; + if ( matches.length === 2 ) { + filterMatch = reAbpFilterExtractor.exec(matches[1].trim()); + if ( filterMatch !== null && filterMatch.length === 2 ) { + out.push(filterMatch[1].trim().replace(/\\\[/g, '[')); + } } - out.push(matches[1].trim().replace(/\\\[/g, '[')); - matches = reAbpExtractor.exec(s); + matches = reAbpSubscriptionExtractor.exec(s); } return out.join('\n'); };