Skip to content
This repository was archived by the owner on Sep 9, 2022. It is now read-only.

Commit 4168ac8

Browse files
committed
Merge branch 'v0.9.5.3'
* v0.9.5.3: - Handle more complex cases of Extended Pseudo Classes - Add support for Adguard :not operator - Added support for using Extended Pseudo Classes in Style filter rule like mycinema.pro#$#[class]:matches-css(width: 336px):matches-css(height: 280px):matches-css(min-height: 280px):has(>ins.adsbygoogle) { visibility: hidden!important; } - Added support for two types of syntax from uBO (+js, +style)
2 parents b839d1b + f2d35d1 commit 4168ac8

9 files changed

+394
-246
lines changed

assets/scriptlets/abort-current-inline-script.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
var randomNo = Math.floor(Math.random() * 2116316160 + 60466176).toString(36);
1616

17-
function abortCurrentInlineScript(api, search = null) {
17+
function abortCurrentInlineScript(api, search = "null") {
1818
let names = api.split(".");
1919
let base = window;
2020
let property;
@@ -28,7 +28,7 @@
2828
var descriptor = Object.getOwnPropertyDescriptor(base, lastproperty);
2929
if ( descriptor && descriptor.get !== undefined ) { return; }
3030

31-
let re = search ? strToRegex(search) : null;
31+
let re = search != "null" ? strToRegex(search) : null;
3232
let rid = randomNo;
3333
let us = document.currentScript;
3434
var value = base[lastproperty];

platform/chromium/manifest.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"manifest_version": 2,
33

44
"name": "uBlock",
5-
"version": "0.9.5.21",
5+
"version": "0.9.5.22",
66

77
"default_locale": "en",
88
"description": "__MSG_extShortDesc__",
@@ -17,7 +17,7 @@
1717
"default_popup": "popup.html"
1818
},
1919

20-
"author": "The uBlock Development Team",
20+
"author": "All uBlock contributors",
2121
"background": {
2222
"page": "background.html"
2323
},

src/js/background.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ return {
9191

9292
// read-only
9393
systemSettings: {
94-
compiledMagic: 'wertpszukpslklk',
95-
selfieMagic: 'werthiasrslklk'
94+
compiledMagic: 'wertpszukpslfds',
95+
selfieMagic: 'werthiasrslfds'
9696
},
9797
restoreBackupSettings: {
9898
lastRestoreFile: '',

src/js/contentscript-end.js

+295-192
Large diffs are not rendered by default.

src/js/contentscript-start.js

+5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ vAPI.contentscriptStartInjected = true;
5656
vAPI.styles = vAPI.styles || [];
5757
vAPI.userStyles = vAPI.userStyles || [];
5858
vAPI.injectedProcedureCosmeticFilters = vAPI.injectedProcedureCosmeticFilters || [];
59+
vAPI.shouldObserveAttributes = false;
60+
vAPI.shouldObserveCharacterData = false;
61+
5962

6063
/******************************************************************************/
6164

@@ -80,6 +83,8 @@ var cosmeticFilters = function(details) {
8083
vAPI.hideCosmeticFilters = details.cosmeticHide;
8184
vAPI.injectedSelectors = details.injectedSelectors;
8285
vAPI.hideProcedureFilters = hideProcedureFilters;
86+
vAPI.shouldObserveAttributes = details.shouldObserveAttributes;
87+
vAPI.shouldObserveCharacterData = details.shouldObserveCharacterData;
8388
let highGenericsArray = [];
8489
if(highGenerics) {
8590
if(highGenerics.hideLow.length > 0) {

src/js/cosmetic-filtering.js

+86-24
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
[ ':contains', ["(", ")", [1, -1], ":-abp-contains"] ]
9494
]);
9595
this.extended = false;
96+
this.snippet = false;
9697
return this;
9798
};
9899

@@ -125,6 +126,21 @@
125126
}
126127
return str;
127128
}
129+
FilterParser.prototype.convertuBOStyleToABP = function(suffix, spos) {
130+
let stylePrefix = suffix.slice(0, spos);
131+
let styleSuffix = suffix.slice(spos);
132+
let style = /:style\(([^)]+)\)/.exec(styleSuffix)[1];
133+
return `${stylePrefix} {${style}}`;
134+
}
135+
FilterParser.prototype.convertuBOJsToABP = function(suffix) {
136+
let invalid = false;
137+
let arrParams = /^\+js\(([^)]+)\)/.exec(suffix)[1].replace(/,[\s]+/gi," ").replace(".js","").split(" ");
138+
let snippetName = arrParams[0];
139+
if(!supportedSnippet.has(snippetName)) {
140+
invalid = true;
141+
}
142+
return [invalid, arrParams.join(" ")];
143+
}
128144
FilterParser.prototype.parse = function(s) {
129145
// important!
130146
this.reset();
@@ -154,21 +170,32 @@
154170
if ( this.suffix.charAt(1) === '[' && this.suffix.slice(2, 9) === 'href^="' ) {
155171
this.suffix = this.suffix.slice(1);
156172
}
173+
157174
this.type = matches[2].charAt(1);
158175
if(reAdguardExtCssSyntax.test(this.suffix)) {
159176
this.suffix = this.convertAdGuardRule(this.suffix);
160177
}
161-
178+
let spos = this.suffix.indexOf(":style");
179+
if(spos !== -1) {
180+
this.suffix = this.convertuBOStyleToABP(this.suffix, spos);
181+
this.type = '$';
182+
}
183+
if(/^\+js\(/.test(this.suffix)) {
184+
[this.invalid, this.suffix] = this.convertuBOJsToABP(this.suffix);
185+
if(this.invalid) return this;
186+
this.type = '$';
187+
}
162188
if(this.type == "$") {
163189
if(reAdguardCssSyntax.test(this.suffix)) {
164-
this.extended = false;
190+
if(reprocSelector.test(this.suffix))
191+
this.extended = true;
165192
} else {
166193
let m = /([^\s]+)/.exec(this.suffix);
167194
if(!supportedSnippet.has(m[0])) {
168195
this.invalid = true;
169196
return this;
170197
}
171-
this.extended = true;
198+
this.snippet = true;
172199
}
173200
}
174201
this.unhide = this.type === '@' ? 1 : 0;
@@ -677,28 +704,29 @@
677704
return {text: content.substring(startIndex, i), end: i};
678705
}
679706

680-
const normalizedOperators = new Set(['-abp-contains', '-abp-has', '-abp-properties' , 'matches-css', 'matches-css-after', 'matches-css-before']);
707+
const normalizedOperators = new Set(['-abp-contains', '-abp-has', '-abp-properties' , 'matches-css', 'matches-css-after', 'matches-css-before', 'not']);
681708
const shortNames = new Map([
682709
["pseudoCls", "ps"],
683710
["prefix", "pf"],
684711
["selectorText", "st"],
685712
["_innerSelectors", "_is"],
686-
["maybeContainsSiblingCombinators", "csc"],
713+
["startsWithSiblingOperator", "sso"],
687714
["hasParallelSiblingSelector", "pss"]
688715
]);
689716

690717
FilterContainer.prototype.parseProcedure = function(expression) {
691718
let tasks = [], prefix, remaining, parsed, selectorText, isValid = true, procSelector = null, pseudoClass = null;
692719
let matches = pseudoClassReg.exec(expression);
693720
if(!matches) {
721+
this.shouldObserveAttributes = !this.shouldObserveAttributes ? /[#.]|\[.+\]/.test(expression) : true;
694722
return [true,
695723
[{
696724
["plain"]: {
697725
[shortNames.get('pseudoCls')]: null,
698726
[shortNames.get('prefix')]: "",
699727
[shortNames.get('selectorText')]: expression,
700728
[shortNames.get('_innerSelectors')]: null,
701-
[shortNames.get('maybeContainsSiblingCombinators')]: /[~+]/.test(expression),
729+
[shortNames.get('startsWithSiblingOperator')]: /^\s*[+~]/.test(expression),
702730
[shortNames.get('hasParallelSiblingSelector')]: false
703731
}
704732
}]
@@ -713,7 +741,12 @@
713741
selectorText = parsed.text;
714742
pseudoClass = (matches[3] == "matches-css-after" ? ":after" : (matches[3] == "matches-css-before" ? ":before" : null ));
715743

716-
if(matches[3] == "-abp-has") {
744+
if(matches[3] == "-abp-contains")
745+
this.shouldObserveCharacterData = true;
746+
747+
this.shouldObserveAttributes = !this.shouldObserveAttributes ? /[#.]|\[.+\]/.test(prefix) : true;
748+
749+
if(matches[3] == "-abp-has" || matches[3] == "not") {
717750
[isValid, procSelector] = this.parseProcedure(selectorText);
718751
} else if(normalizedOperators.has(matches[3])) {
719752
isValid = true;
@@ -728,6 +761,7 @@
728761
[shortNames.get('prefix')]: prefix,
729762
[shortNames.get('selectorText')]: procSelector === null ? selectorText : null,
730763
[shortNames.get('_innerSelectors')]: procSelector,
764+
[shortNames.get('startsWithSiblingOperator')]: /^\s*[+~]/.test(prefix),
731765
[shortNames.get('hasParallelSiblingSelector')]: false
732766
}
733767
});
@@ -736,11 +770,11 @@
736770
let suffix;
737771
[isValid, suffix] = this.parseProcedure(suffixtext);
738772
if(isValid) {
739-
if(Object.keys(suffix).length == 1) {
740-
if(Object.keys(suffix)[0] == "plain" && suffix["plain"].maybeContainsSiblingCombinators) {
773+
if(suffix.length > 0) {
774+
if(Object.values(suffix[0])[0][shortNames.get('startsWithSiblingOperator')]) {
741775
for (let task of tasks) {
742-
if(Object.keys(task)[0] == "-abp-has" || Object.keys(task)[0] == "-abp-contains" || Object.keys(task)[0] == "-abp-properties") {
743-
task[Object.keys(task)[0]].hasParallelSiblingSelector = true;
776+
if(Object.keys(task)[0] != "plain") {
777+
task[Object.keys(task)[0]][shortNames.get('hasParallelSiblingSelector')] = true;
744778
}
745779
}
746780
}
@@ -772,19 +806,33 @@
772806

773807
let isValid;
774808
this.pseudoClassExpression = false;
775-
if(this.parser.type == "$" && this.parser.extended) {
776-
isValid = true;
777-
} else if(this.parser.type == "$" && !this.parser.extended) {
778-
let matches = /(.+?)\s*\{(.*)\}\s*$/.exec(parsed.suffix);
779-
isValid = this.isValidSelector(matches[1].trim()) && isValidStyle(matches[2].trim());
809+
this.shouldObserveAttributes = false;
810+
this.shouldObserveCharacterData = false;
811+
812+
if(this.parser.type == "$") {
813+
if(this.parser.snippet)
814+
isValid = true;
815+
else if(this.parser.extended) {
816+
let matches = /(.+?)\s*\{(.*)\}\s*$/.exec(parsed.suffix);
817+
isValid = this.isValidSelector(matches[1].trim());
818+
if(!isValid && reprocSelector.test(matches[1].trim()) && isValidStyle(matches[2].trim())) {
819+
let tasks;
820+
[isValid, tasks] = this.parseProcedure(matches[1].trim());
821+
this.pseudoClassExpression = true;
822+
parsed.suffix = JSON.stringify({'tasks': tasks, 'style': matches[2].trim(), 'attr': this.shouldObserveAttributes, 'data': this.shouldObserveCharacterData});
823+
}
824+
} else {
825+
let matches = /(.+?)\s*\{(.*)\}\s*$/.exec(parsed.suffix);
826+
isValid = this.isValidSelector(matches[1].trim()) && isValidStyle(matches[2].trim());
827+
}
780828
}
781829
else {
782830
isValid = this.isValidSelector(parsed.suffix);
783831
if(!isValid && reprocSelector.test(parsed.suffix)) {
784832
let tasks;
785833
[isValid, tasks] = this.parseProcedure(parsed.suffix);
786834
this.pseudoClassExpression = true;
787-
parsed.suffix = JSON.stringify(tasks);
835+
parsed.suffix = JSON.stringify({'tasks': tasks, 'style': "", 'attr': this.shouldObserveAttributes, 'data': this.shouldObserveCharacterData});
788836
}
789837
}
790838
// For hostname- or entity-based filters, class- or id-based selectors are
@@ -911,9 +959,9 @@
911959
hash = this.pseudoClassExpression ? makeHash(unhide, domain, this.domainHashMask, this.procedureMask) : makeHash(unhide, domain, this.domainHashMask);
912960
}
913961
let hshash = µb.tokenHash(hostname);
914-
if(parsed.type == "$" && parsed.extended)
962+
if(parsed.type == "$" && parsed.snippet)
915963
out.push(['hs+', hash, hshash, parsed.suffix]);
916-
else if(parsed.type == "$" && !parsed.extended)
964+
else if(parsed.type == "$")
917965
out.push(['hs', hash, hshash, parsed.suffix]);
918966
else
919967
out.push(['h', hash, hshash, parsed.suffix]);
@@ -923,9 +971,9 @@
923971

924972
FilterContainer.prototype.compileEntitySelector = function(hostname, parsed, out) {
925973
let entity = hostname.slice(0, -2);
926-
if(parsed.type == "$" && parsed.extended)
974+
if(parsed.type == "$" && parsed.snippet)
927975
out.push(['es+', entity, parsed.suffix]);
928-
else if(parsed.type == "$" && !parsed.extended)
976+
else if(parsed.type == "$")
929977
out.push(['es', entity, parsed.suffix]);
930978
else
931979
out.push(['e', entity, parsed.suffix]);
@@ -1359,9 +1407,11 @@
13591407
cosmeticDonthide: [],
13601408
netHide: [],
13611409
netCollapse: µb.userSettings.collapseBlocked,
1362-
cosmeticUserCss: []
1410+
cosmeticUserCss: [],
1411+
shouldObserveAttributes: false,
1412+
shouldObserveCharacterData: false
13631413
};
1364-
if(options.skipCosmeticFiltering){
1414+
if(options.skipCosmeticFiltering) {
13651415
return r;
13661416
}
13671417

@@ -1401,6 +1451,9 @@
14011451
if(this.hostnameFilterDataView.hasOwnProperty("style")) {
14021452
hash = makeHash(0, domain, this.domainHashMask);
14031453
this.hostnameFilterDataView["style"].retrieve(hosthashes, hash, r.cosmeticUserCss);
1454+
1455+
hash = makeHash(0, domain, this.domainHashMask, this.procedureMask);
1456+
this.hostnameFilterDataView["style"].retrieve(hosthashes, hash, r.procedureHide);
14041457
}
14051458

14061459
// No entity exceptions as of now
@@ -1410,8 +1463,17 @@
14101463
hash = makeHash(0, domain, this.domainHashMask, this.procedureMask);
14111464
this.hostnameFilterDataView[flag].retrieve(hosthashes, hash, r.procedureHide);
14121465

1466+
if(r.procedureHide.length > 0) {
1467+
r.shouldObserveAttributes = r.procedureHide.some(selector => selector.indexOf("\"attr\":true") !== -1);
1468+
r.shouldObserveCharacterData = r.procedureHide.some(selector => selector.indexOf("\"data\":true") !== -1);
1469+
}
1470+
14131471
if(request.procedureSelectorsOnly) {
1414-
return r.procedureHide;
1472+
return {
1473+
procedureHide :r.procedureHide,
1474+
shouldObserveAttributes: r.shouldObserveAttributes,
1475+
shouldObserveCharacterData: r.shouldObserveCharacterData
1476+
};
14151477
}
14161478

14171479
// https://github.com/uBlockAdmin/uBlock/issues/188

src/js/messaging.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ var onMessage = function(request, sender, callback) {
548548
};
549549
if(!response.shutdown && !pageStore.applyDocumentFiltering) {
550550
if ( request.selectors != "" ) {
551-
details.code = request.selectors + '\n{display:none!important;}';
551+
details.code = request.selectors;
552552
vAPI.insertCSS(request.tabId, details);
553553
}
554554
}

src/js/storage.js

-22
Original file line numberDiff line numberDiff line change
@@ -196,25 +196,6 @@
196196
µBlock.getAvailableLists = function(callback) {
197197
var availableLists = {};
198198
var relocationMap = {};
199-
let tempFLChangeMap = new Map([
200-
["assets/thirdparties/abp-filters-anti-cv/english.txt", "assets/thirdparties/raw.githubusercontent.com/abp-filters-anti-cv/english.txt"],
201-
["assets/thirdparties/adblock-nocoin-list/nocoin.txt", "assets/thirdparties/raw.githubusercontent.com/adblock-nocoin-list/nocoin.txt"],
202-
["assets/thirdparties/cjxlist1.googlecode.com/svn/cjxlist.txt", "assets/thirdparties/raw.githubusercontent.com/cjx82630/cjxlist/cjxlist.txt"],
203-
["assets/thirdparties/dl.dropboxusercontent.com/u/1289327/abpxfiles/filtri.txt", "assets/thirdparties/raw.githubusercontent.com/gioxx/filtri.txt"],
204-
["assets/thirdparties/gitorious.org/adblock-latvian/adblock-latvian/raw/master_lists/latvian-list.txt", "assets/thirdparties/adblock-latvian/latvian-list.txt"],
205-
["assets/thirdparties/home.fredfiber.no/langsholt/adblock.txt", "assets/thirdparties/raw.githubusercontent.com/DandelionSprout/adfilt/NorwegianList.txt"],
206-
["assets/thirdparties/indonesianadblockrules.googlecode.com/hg/subscriptions/abpindo.txt", "assets/thirdparties/raw.githubusercontent.com/indonesianadblockrules/subscriptions/abpindo.txt"],
207-
["assets/thirdparties/liste-ar-adblock.googlecode.com/hg/Liste_AR.txt", "assets/thirdparties/easylist-downloads.adblockplus.org/Liste_AR.txt"],
208-
["assets/thirdparties/raw.githubusercontent.com/AdBlockPlusIsrael/EasyListHebrew/master/EasyListHebrew.txt", "assets/thirdparties/raw.githubusercontent.com/EasyListHebrew/master/EasyListHebrew.txt"],
209-
["assets/thirdparties/raw.githubusercontent.com/adblockpolska/Adblock_PL_List/master/adblock_polska.txt", "assets/thirdparties/raw.githubusercontent.com/polish-adblock-filters/adblock.txt"],
210-
["assets/thirdparties/raw.githubusercontent.com/wiltteri/wiltteri.txt/master/wiltteri.txt", "assets/thirdparties/raw.githubusercontent.com/finnish-easylist-addition/Finland_adb.txt"],
211-
["assets/thirdparties/spam404bl.com/spam404scamlist.txt", "assets/thirdparties/raw.githubusercontent.com/Spam404/lists/adblock-list.txt"],
212-
["assets/thirdparties/www.fanboy.co.nz/fanboy-korean.txt", "assets/thirdparties/raw.githubusercontent.com/adblock-korea-contrib/filter.txt"],
213-
["assets/thirdparties/www.fanboy.co.nz/fanboy-swedish.txt", "assets/thirdparties/raw.githubusercontent.com/Frellwits-filter-lists/Frellwits-Swedish-Filter.txt"],
214-
["assets/thirdparties/www.fanboy.co.nz/fanboy-vietnam.txt", "assets/thirdparties/raw.githubusercontent.com/abpvn/abpvn.txt"],
215-
["assets/thirdparties/www.zoso.ro/pages/rolist.txt", "assets/thirdparties/raw.githubusercontent.com/ROad-Block/road-block-filters-light.txt"]
216-
]);
217-
218199
var locationOfAA = 'assets/thirdparties/easylist-downloads.adblockplus.org/exceptionrules.txt';
219200
var fixLocation = function(location) {
220201
// https://github.com/uBlockAdmin/uBlock/issues/418
@@ -244,9 +225,6 @@
244225
off = lists[location].off === true;
245226
}
246227
}
247-
if(tempFLChangeMap.has(location)) {
248-
location = tempFLChangeMap.get(location);
249-
}
250228
availableEntry = availableLists[location];
251229
if ( availableEntry === undefined ) {
252230
µb.purgeFilterList(location);

src/js/ublock.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ https://github.com/darkskyapp/string-hash/blob/master/index.js
757757
reParams.lastIndex = 0;
758758
let matches;
759759
while ( matches = reParams.exec(scriptlets)) {
760-
scriptlets = scriptlets.replace(matches[0], args[matches[2] - 1]);
760+
scriptlets = scriptlets.replace(matches[0], args[matches[2] - 1] === undefined ? null : args[matches[2] - 1]);
761761
}
762762
return scriptlets;
763763
}

0 commit comments

Comments
 (0)