mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 03:12:33 +01:00
Fix not highlighting cases of invalid syntax
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/1791 The following case of invalid syntax was not reported as invalid by the syntax highlighter: ... example.com image ... With dynamic filtering, there can't be a specific hostname when a specific type is used, or a specific type when a specific hostname is used, one or the other must be `*`.
This commit is contained in:
parent
fa3c4623ea
commit
2ab39aee23
@ -123,6 +123,7 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
||||
const { sortType } = opts;
|
||||
const reNotToken = /^\s+/;
|
||||
const reToken = /^\S+/;
|
||||
const tokens = [];
|
||||
// leading whitespaces
|
||||
let match = reNotToken.exec(string);
|
||||
if ( match !== null ) {
|
||||
@ -131,6 +132,7 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
||||
// first token
|
||||
match = reToken.exec(string);
|
||||
if ( match === null ) { return; }
|
||||
tokens.push(match[0]);
|
||||
// hostname or switch
|
||||
const isSwitchRule = validSwitches.has(match[0]);
|
||||
if ( isSwitchRule ) {
|
||||
@ -151,6 +153,7 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
||||
// second token
|
||||
match = reToken.exec(string);
|
||||
if ( match === null ) { return; }
|
||||
tokens.push(match[0]);
|
||||
// hostname or url
|
||||
const isURLRule = isSwitchRule === false && match[0].indexOf('://') > 0;
|
||||
if ( isURLRule ) {
|
||||
@ -169,6 +172,7 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
||||
// third token
|
||||
match = reToken.exec(string);
|
||||
if ( match === null ) { return; }
|
||||
tokens.push(match[0]);
|
||||
// rule type or switch state
|
||||
if ( isSwitchRule ) {
|
||||
string = validSwitcheStates.has(match[0])
|
||||
@ -178,10 +182,14 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
||||
string = invalidURLRuleTypes.has(match[0])
|
||||
? addMatchSlice(match, 'error')
|
||||
: addMatchSlice(match);
|
||||
} else {
|
||||
} else if ( tokens[1] === '*' ) {
|
||||
string = validHnRuleTypes.has(match[0])
|
||||
? addMatchSlice(match)
|
||||
: addMatchSlice(match, 'error');
|
||||
} else {
|
||||
string = match[0] === '*'
|
||||
? addMatchSlice(match)
|
||||
: addMatchSlice(match, 'error');
|
||||
}
|
||||
// whitespaces before fourth token
|
||||
match = reNotToken.exec(string);
|
||||
@ -190,6 +198,7 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
||||
// fourth token
|
||||
match = reToken.exec(string);
|
||||
if ( match === null ) { return; }
|
||||
tokens.push(match[0]);
|
||||
string = isSwitchRule || validActions.has(match[0]) === false
|
||||
? addMatchSlice(match, 'error')
|
||||
: addMatchSlice(match, `${match[0]}rule`);
|
||||
|
Loading…
Reference in New Issue
Block a user