1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-01 16:33:06 +01:00

Hightlight to warn about unknown redirect tokens

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/1134
This commit is contained in:
Raymond Hill 2020-10-11 08:59:44 -04:00
parent 6ff72af4aa
commit 1727585faa
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -177,6 +177,56 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
return null;
};
const colorNetOptionValueSpan = function(stream, bits) {
const { pos, string } = stream;
let style;
// Warn about unknown redirect tokens.
if (
string.charCodeAt(pos - 1) === 0x3D /* '=' */ &&
/[$,]redirect(-rule)?=$/.test(string.slice(0, pos))
) {
style = 'value';
let end = parser.skipUntil(
parserSlot,
parser.commentSpan.i,
parser.BITComma
);
const token = parser.strFromSlices(parserSlot, end - 3);
if ( redirectNames.has(token) === false ) {
style += ' warning';
}
stream.pos += token.length;
parserSlot = end;
return style;
}
if ( (bits & parser.BITTilde) !== 0 ) {
style = 'keyword strong';
} else if ( (bits & parser.BITPipe) !== 0 ) {
style = 'def';
}
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return style || 'value';
};
const colorNetOptionSpan = function(stream) {
const bits = parser.slices[parserSlot];
let style;
if ( (bits & parser.BITComma) !== 0 ) {
style = 'def strong';
netOptionValueMode = false;
} else if ( netOptionValueMode ) {
return colorNetOptionValueSpan(stream, bits);
} else if ( (bits & parser.BITTilde) !== 0 ) {
style = 'keyword strong';
} else if ( (bits & parser.BITEqual) !== 0 ) {
netOptionValueMode = true;
}
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return style || 'def';
};
const colorNetSpan = function(stream) {
if ( parserSlot < parser.exceptionSpan.i ) {
stream.pos += parser.slices[parserSlot+2];
@ -236,23 +286,7 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
parserSlot >= parser.optionsSpan.i &&
parserSlot < parser.commentSpan.i
) {
const bits = parser.slices[parserSlot];
let style;
if ( (bits & parser.BITComma) !== 0 ) {
style = 'def strong';
netOptionValueMode = false;
} else if ( (bits & parser.BITTilde) !== 0 ) {
style = 'keyword strong';
} else if ( (bits & parser.BITPipe) !== 0 ) {
style = 'def';
} else if ( netOptionValueMode ) {
style = 'value';
} else if ( (bits & parser.BITEqual) !== 0 ) {
netOptionValueMode = true;
}
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return style || 'def';
return colorNetOptionSpan(stream);
}
if (
parserSlot >= parser.commentSpan.i &&