Skip to content

Commit

Permalink
Auto-escape commas in removeparam's regexes
Browse files Browse the repository at this point in the history
Related feedback:
- uBlockOrigin/uBlock-issues#760 (comment)

This is a quick fix, some refactoring necessary for a more
comprehensive fix to all such issues.
  • Loading branch information
gorhill committed Oct 26, 2021
1 parent f5001c0 commit c136c7b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
27 changes: 16 additions & 11 deletions src/js/codemirror/ubo-static-filtering.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,25 +208,30 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
return style || 'value';
};

// https://github.com/uBlockOrigin/uBlock-issues/issues/760#issuecomment-951146371
// Quick fix: auto-escape commas.
const colorNetOptionSpan = function(stream) {
const bits = parser.slices[parserSlot];
if ( (bits & parser.BITComma) !== 0 ) {
netOptionValueMode = false;
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return 'def strong';
const [ slotBits, slotPos, slotLen ] =
parser.slices.slice(parserSlot, parserSlot+3);
if ( (slotBits & parser.BITComma) !== 0 ) {
if ( /^,\d*?\}/.test(parser.raw.slice(slotPos)) === false ) {
netOptionValueMode = false;
stream.pos += slotLen;
parserSlot += 3;
return 'def strong';
}
}
if ( netOptionValueMode ) {
return colorNetOptionValueSpan(stream, bits);
return colorNetOptionValueSpan(stream, slotBits);
}
if ( (bits & parser.BITTilde) !== 0 ) {
stream.pos += parser.slices[parserSlot+2];
if ( (slotBits & parser.BITTilde) !== 0 ) {
stream.pos += slotLen;
parserSlot += 3;
return 'keyword strong';
}
if ( (bits & parser.BITEqual) !== 0 ) {
if ( (slotBits & parser.BITEqual) !== 0 ) {
netOptionValueMode = true;
stream.pos += parser.slices[parserSlot+2];
stream.pos += slotLen;
parserSlot += 3;
return 'def';
}
Expand Down
14 changes: 9 additions & 5 deletions src/js/static-filtering-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -1884,9 +1884,9 @@ const BITUnderscore = 1 << 22;
const BITBrace = 1 << 23;
const BITPipe = 1 << 24;
const BITTilde = 1 << 25;
const BITOpening = 1 << 27;
const BITClosing = 1 << 28;
const BITUnicode = 1 << 29;
const BITOpening = 1 << 26;
const BITClosing = 1 << 27;
const BITUnicode = 1 << 28;
// TODO: separate from character bits into a new slice slot.
const BITIgnore = 1 << 30;
const BITError = 1 << 31;
Expand Down Expand Up @@ -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 {
constructor(parser) {
this.parser = parser;
Expand Down Expand Up @@ -2426,8 +2429,9 @@ const NetOptionsIterator = class {
if ( hasBits(bits, BITComma) ) {
if ( this.interactive && (i === lopt || slices[i+2] > 1) ) {
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; }
i += 3;
Expand Down Expand Up @@ -2551,7 +2555,7 @@ const NetOptionsIterator = class {
}
}
}
// `queryprune=`: only for network requests.
// `removeparam=`: only for network requests.
{
const i = this.tokenPos[OPTTokenQueryprune];
if ( i !== -1 ) {
Expand Down

0 comments on commit c136c7b

Please sign in to comment.