Skip to content

Commit

Permalink
handle invalid else directive
Browse files Browse the repository at this point in the history
  • Loading branch information
slavaleleka committed Oct 2, 2023
1 parent 31fd9bb commit 5b79151
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/filters-downloader-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ const FiltersDownloaderCreator = (FileDownloadWrapper) => {
result = result.concat(resolveConditions(rulesUnderCondition, definedProperties));
}
} else {
// check if there is something after !#else
if (rules[elseLineIndex].trim().length !== CONDITION_ELSE_DIRECTIVE_START.length) {
throw new Error(`Invalid directives: Found invalid !#else: ${rule}`);
}

if (isConditionMatched) {
const rulesForConditionTrue = rules.slice(i + 1, elseLineIndex);
// Resolve inner conditions in recursion
Expand All @@ -276,9 +281,12 @@ const FiltersDownloaderCreator = (FileDownloadWrapper) => {

// Skip to the end of block
i = endLineIndex;
} else if (rule.indexOf(CONDITION_ELSE_DIRECTIVE_START) === 0) {
// Found !#else without !#if
throw new Error(`Invalid directives: Found unexpected condition else branch: ${rule}`);
} else if (rule.indexOf(CONDITION_DIRECTIVE_END) === 0) {
// Found condition end without start
throw new Error('Invalid directives: Found unexpected condition end: ' + rule);
// Found !#endif without !#if
throw new Error(`Invalid directives: Found unexpected condition end: ${rule}`);
} else {
result.push(rule);
}
Expand Down

0 comments on commit 5b79151

Please sign in to comment.