mirror of
https://github.com/gorhill/uBlock.git
synced 2024-11-07 11:22:38 +01:00
Visually emphasize regex-based pattern
To help prevent mistakenly creating regex-based patterns.
This commit is contained in:
parent
994342506b
commit
08eca13364
@ -26,6 +26,12 @@
|
|||||||
.cm-s-default .cm-string-2 { color: #930; }
|
.cm-s-default .cm-string-2 { color: #930; }
|
||||||
.cm-s-default .cm-comment { color: #777; }
|
.cm-s-default .cm-comment { color: #777; }
|
||||||
.cm-s-default .cm-keyword { color: #90b; }
|
.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,
|
.cm-s-default .cm-error,
|
||||||
.CodeMirror-linebackground.error {
|
.CodeMirror-linebackground.error {
|
||||||
background-color: #ff000018;
|
background-color: #ff000018;
|
||||||
|
@ -104,11 +104,17 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
|
|||||||
parserSlot >= parser.patternSpan.i &&
|
parserSlot >= parser.patternSpan.i &&
|
||||||
parserSlot < parser.patternRightAnchorSpan.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];
|
stream.pos += parser.slices[parserSlot+2];
|
||||||
parserSlot += 3;
|
parserSlot += 3;
|
||||||
return 'keyword strong';
|
return 'keyword strong';
|
||||||
}
|
}
|
||||||
|
let style = 'variable';
|
||||||
|
if ( isRegex ) { style += ' regex'; }
|
||||||
const nextSlot = parser.skipUntil(
|
const nextSlot = parser.skipUntil(
|
||||||
parserSlot,
|
parserSlot,
|
||||||
parser.patternRightAnchorSpan.i,
|
parser.patternRightAnchorSpan.i,
|
||||||
@ -116,7 +122,7 @@ CodeMirror.defineMode("ubo-static-filtering", function() {
|
|||||||
);
|
);
|
||||||
stream.pos = parser.slices[nextSlot+1];
|
stream.pos = parser.slices[nextSlot+1];
|
||||||
parserSlot = nextSlot;
|
parserSlot = nextSlot;
|
||||||
return 'variable';
|
return style;
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
parserSlot === parser.optionsAnchorSpan.i &&
|
parserSlot === parser.optionsAnchorSpan.i &&
|
||||||
|
@ -350,11 +350,10 @@ const Parser = class {
|
|||||||
// https://github.com/gorhill/uBlock/issues/952
|
// https://github.com/gorhill/uBlock/issues/952
|
||||||
// AdGuard-specific `$$` filters => unsupported.
|
// AdGuard-specific `$$` filters => unsupported.
|
||||||
if ( this.findFirstOdd(0, BITHostname | BITComma | BITAsterisk) === i ) {
|
if ( this.findFirstOdd(0, BITHostname | BITComma | BITAsterisk) === i ) {
|
||||||
|
this.flavorBits |= BITFlavorError;
|
||||||
if ( this.interactive ) {
|
if ( this.interactive ) {
|
||||||
this.markSlices(i, i+3, BITError);
|
this.markSlices(i, i+3, BITError);
|
||||||
}
|
}
|
||||||
this.allBits |= BITError;
|
|
||||||
this.flavorBits |= BITFlavorError;
|
|
||||||
} else {
|
} else {
|
||||||
this.splitSlot(i, l - 1);
|
this.splitSlot(i, l - 1);
|
||||||
i += 3;
|
i += 3;
|
||||||
@ -568,8 +567,7 @@ const Parser = class {
|
|||||||
void new RegExp(this.getNetPattern());
|
void new RegExp(this.getNetPattern());
|
||||||
}
|
}
|
||||||
catch (ex) {
|
catch (ex) {
|
||||||
const { i, l } = this.patternSpan;
|
this.markSpan(this.patternSpan, BITError);
|
||||||
this.markSlices(i, i + l, BITError);
|
|
||||||
}
|
}
|
||||||
} else if ( this.patternIsDubious() ) {
|
} else if ( this.patternIsDubious() ) {
|
||||||
this.markSpan(this.patternSpan, BITError);
|
this.markSpan(this.patternSpan, BITError);
|
||||||
@ -979,7 +977,7 @@ const Parser = class {
|
|||||||
}
|
}
|
||||||
|
|
||||||
hasError() {
|
hasError() {
|
||||||
return hasBits(this.allBits, BITError);
|
return hasBits(this.flavorBits, BITFlavorError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user