1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00

Auto-escape commas in removeparam's regexes

Related feedback:
- https://github.com/uBlockOrigin/uBlock-issues/issues/760#issuecomment-951146371

This is a quick fix, some refactoring necessary for a more
comprehensive fix to all such issues.
This commit is contained in:
Raymond Hill 2021-10-26 08:51:55 -04:00
parent f5001c03aa
commit c136c7b454
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
2 changed files with 25 additions and 16 deletions

View File

@ -208,25 +208,30 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
return style || 'value'; return style || 'value';
}; };
// https://github.com/uBlockOrigin/uBlock-issues/issues/760#issuecomment-951146371
// Quick fix: auto-escape commas.
const colorNetOptionSpan = function(stream) { const colorNetOptionSpan = function(stream) {
const bits = parser.slices[parserSlot]; const [ slotBits, slotPos, slotLen ] =
if ( (bits & parser.BITComma) !== 0 ) { parser.slices.slice(parserSlot, parserSlot+3);
if ( (slotBits & parser.BITComma) !== 0 ) {
if ( /^,\d*?\}/.test(parser.raw.slice(slotPos)) === false ) {
netOptionValueMode = false; netOptionValueMode = false;
stream.pos += parser.slices[parserSlot+2]; stream.pos += slotLen;
parserSlot += 3; parserSlot += 3;
return 'def strong'; return 'def strong';
} }
if ( netOptionValueMode ) {
return colorNetOptionValueSpan(stream, bits);
} }
if ( (bits & parser.BITTilde) !== 0 ) { if ( netOptionValueMode ) {
stream.pos += parser.slices[parserSlot+2]; return colorNetOptionValueSpan(stream, slotBits);
}
if ( (slotBits & parser.BITTilde) !== 0 ) {
stream.pos += slotLen;
parserSlot += 3; parserSlot += 3;
return 'keyword strong'; return 'keyword strong';
} }
if ( (bits & parser.BITEqual) !== 0 ) { if ( (slotBits & parser.BITEqual) !== 0 ) {
netOptionValueMode = true; netOptionValueMode = true;
stream.pos += parser.slices[parserSlot+2]; stream.pos += slotLen;
parserSlot += 3; parserSlot += 3;
return 'def'; return 'def';
} }

View File

@ -1884,9 +1884,9 @@ const BITUnderscore = 1 << 22;
const BITBrace = 1 << 23; const BITBrace = 1 << 23;
const BITPipe = 1 << 24; const BITPipe = 1 << 24;
const BITTilde = 1 << 25; const BITTilde = 1 << 25;
const BITOpening = 1 << 27; const BITOpening = 1 << 26;
const BITClosing = 1 << 28; const BITClosing = 1 << 27;
const BITUnicode = 1 << 29; const BITUnicode = 1 << 28;
// TODO: separate from character bits into a new slice slot. // TODO: separate from character bits into a new slice slot.
const BITIgnore = 1 << 30; const BITIgnore = 1 << 30;
const BITError = 1 << 31; const BITError = 1 << 31;
@ -2359,6 +2359,9 @@ const Span = class {
/******************************************************************************/ /******************************************************************************/
// https://github.com/uBlockOrigin/uBlock-issues/issues/760#issuecomment-951146371
// Quick fix: auto-escape commas.
const NetOptionsIterator = class { const NetOptionsIterator = class {
constructor(parser) { constructor(parser) {
this.parser = parser; this.parser = parser;
@ -2426,9 +2429,10 @@ const NetOptionsIterator = class {
if ( hasBits(bits, BITComma) ) { if ( hasBits(bits, BITComma) ) {
if ( this.interactive && (i === lopt || slices[i+2] > 1) ) { if ( this.interactive && (i === lopt || slices[i+2] > 1) ) {
slices[i] |= BITError; slices[i] |= BITError;
} } else if ( /^,\d*?\}/.test(this.parser.raw.slice(slices[i+1])) === false ) {
break; break;
} }
}
if ( lval === 0 && hasBits(bits, BITEqual) ) { lval = i; } if ( lval === 0 && hasBits(bits, BITEqual) ) { lval = i; }
i += 3; i += 3;
} }
@ -2551,7 +2555,7 @@ const NetOptionsIterator = class {
} }
} }
} }
// `queryprune=`: only for network requests. // `removeparam=`: only for network requests.
{ {
const i = this.tokenPos[OPTTokenQueryprune]; const i = this.tokenPos[OPTTokenQueryprune];
if ( i !== -1 ) { if ( i !== -1 ) {