Skip to content

Commit 6cac645

Browse files
committed
Do not discard !#else block for unknown preprocessor tokens
Related issue: uBlockOrigin/uBlock-issues#3393
1 parent 3d6984a commit 6cac645

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

src/js/static-filtering-parser.js

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4430,14 +4430,14 @@ export const utils = (( ) => {
44304430
const parts = [ 0 ];
44314431
let discard = false;
44324432

4433-
const shouldDiscard = ( ) => stack.some(v => v);
4433+
const shouldDiscard = ( ) => stack.some(v => v.known && v.discard);
44344434

4435-
const begif = (startDiscard, match) => {
4436-
if ( discard === false && startDiscard ) {
4437-
parts.push(match.index);
4435+
const begif = details => {
4436+
if ( discard === false && details.known && details.discard ) {
4437+
parts.push(details.pos);
44384438
discard = true;
44394439
}
4440-
stack.push(startDiscard);
4440+
stack.push(details);
44414441
};
44424442

44434443
const endif = match => {
@@ -4455,15 +4455,21 @@ export const utils = (( ) => {
44554455

44564456
switch ( match[1] ) {
44574457
case 'if': {
4458-
const startDiscard = this.evaluateExpr(match[2].trim(), env) === false;
4459-
begif(startDiscard, match);
4458+
const result = this.evaluateExpr(match[2].trim(), env);
4459+
begif({
4460+
known: result !== undefined,
4461+
discard: result === false,
4462+
pos: match.index,
4463+
});
44604464
break;
44614465
}
44624466
case 'else': {
44634467
if ( stack.length === 0 ) { break; }
4464-
const startDiscard = stack[stack.length-1] === false;
4468+
const details = stack[stack.length-1];
44654469
endif(match);
4466-
begif(startDiscard, match);
4470+
details.discard = details.discard === false;
4471+
details.pos = match.index;
4472+
begif(details);
44674473
break;
44684474
}
44694475
case 'endif': {

0 commit comments

Comments
 (0)