1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-22 02:12:44 +01:00

Do not discard !#else block for unknown preprocessor tokens

Related issue:
https://github.com/uBlockOrigin/uBlock-issues/issues/3393
This commit is contained in:
Raymond Hill 2024-09-30 10:16:48 -04:00
parent 3d6984aeaf
commit 6cac645830
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -4430,14 +4430,14 @@ export const utils = (( ) => {
const parts = [ 0 ];
let discard = false;
const shouldDiscard = ( ) => stack.some(v => v);
const shouldDiscard = ( ) => stack.some(v => v.known && v.discard);
const begif = (startDiscard, match) => {
if ( discard === false && startDiscard ) {
parts.push(match.index);
const begif = details => {
if ( discard === false && details.known && details.discard ) {
parts.push(details.pos);
discard = true;
}
stack.push(startDiscard);
stack.push(details);
};
const endif = match => {
@ -4455,15 +4455,21 @@ export const utils = (( ) => {
switch ( match[1] ) {
case 'if': {
const startDiscard = this.evaluateExpr(match[2].trim(), env) === false;
begif(startDiscard, match);
const result = this.evaluateExpr(match[2].trim(), env);
begif({
known: result !== undefined,
discard: result === false,
pos: match.index,
});
break;
}
case 'else': {
if ( stack.length === 0 ) { break; }
const startDiscard = stack[stack.length-1] === false;
const details = stack[stack.length-1];
endif(match);
begif(startDiscard, match);
details.discard = details.discard === false;
details.pos = match.index;
begif(details);
break;
}
case 'endif': {