Visually emphasize regex-based pattern

To help prevent mistakenly creating regex-based
patterns.
This commit is contained in:
Raymond Hill 2020-06-08 12:39:31 -04:00
parent 994342506b
commit 08eca13364
No known key found for this signature in database
GPG key ID: 25E1490B761470C2
3 changed files with 17 additions and 7 deletions

View file

@ -26,6 +26,12 @@
.cm-s-default .cm-string-2 { color: #930; }
.cm-s-default .cm-comment { color: #777; }
.cm-s-default .cm-keyword { color: #90b; }
.cm-s-default .cm-regex {
text-underline-position: under;
text-decoration-color: darkgray;
text-decoration-style: solid;
text-decoration-line: underline;
}
.cm-s-default .cm-error,
.CodeMirror-linebackground.error {
background-color: #ff000018;

View file

@ -104,11 +104,17 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
parserSlot >= parser.patternSpan.i &&
parserSlot < parser.patternRightAnchorSpan.i
) {
if ( (parser.slices[parserSlot] & (parser.BITAsterisk | parser.BITCaret)) !== 0 ) {
const isRegex = parser.patternIsRegex();
if (
(isRegex === false) &&
(parser.slices[parserSlot] & (parser.BITAsterisk | parser.BITCaret)) !== 0
) {
stream.pos += parser.slices[parserSlot+2];
parserSlot += 3;
return 'keyword strong';
}
let style = 'variable';
if ( isRegex ) { style += ' regex'; }
const nextSlot = parser.skipUntil(
parserSlot,
parser.patternRightAnchorSpan.i,
@ -116,7 +122,7 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
);
stream.pos = parser.slices[nextSlot+1];
parserSlot = nextSlot;
return 'variable';
return style;
}
if (
parserSlot === parser.optionsAnchorSpan.i &&

View file

@ -350,11 +350,10 @@ const Parser = class {
// https://github.com/gorhill/uBlock/issues/952
// AdGuard-specific `$$` filters => unsupported.
if ( this.findFirstOdd(0, BITHostname | BITComma | BITAsterisk) === i ) {
this.flavorBits |= BITFlavorError;
if ( this.interactive ) {
this.markSlices(i, i+3, BITError);
}
this.allBits |= BITError;
this.flavorBits |= BITFlavorError;
} else {
this.splitSlot(i, l - 1);
i += 3;
@ -568,8 +567,7 @@ const Parser = class {
void new RegExp(this.getNetPattern());
}
catch (ex) {
const { i, l } = this.patternSpan;
this.markSlices(i, i + l, BITError);
this.markSpan(this.patternSpan, BITError);
}
} else if ( this.patternIsDubious() ) {
this.markSpan(this.patternSpan, BITError);
@ -979,7 +977,7 @@ const Parser = class {
}
hasError() {
return hasBits(this.allBits, BITError);
return hasBits(this.flavorBits, BITFlavorError);
}
};