mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-18 08:52:26 +02:00
Fix highlighting of good/bad hostnames in "My rules" pane
Related feedback: - https://github.com/uBlockOrigin/uBlock-issues/issues/1249#issuecomment-695755743
This commit is contained in:
parent
5f8c63e96e
commit
6b15e8c423
@ -56,12 +56,25 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
|||||||
'allow',
|
'allow',
|
||||||
'noop',
|
'noop',
|
||||||
]);
|
]);
|
||||||
const reIsNotHostname = /[:/#?*]/;
|
const hnValidator = new URL(self.location.href);
|
||||||
|
const reBadHn = /[%]|^\.|\.$/;
|
||||||
const slices = [];
|
const slices = [];
|
||||||
let sliceIndex = 0;
|
let sliceIndex = 0;
|
||||||
const tokens = [];
|
const tokens = [];
|
||||||
let tokenIndex = 0;
|
let tokenIndex = 0;
|
||||||
|
|
||||||
|
const isValidHostname = hnin => {
|
||||||
|
if ( hnin === '*' ) { return true; }
|
||||||
|
hnValidator.hostname = '_';
|
||||||
|
try {
|
||||||
|
hnValidator.hostname = hnin;
|
||||||
|
} catch(_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
const hnout = hnValidator.hostname;
|
||||||
|
return hnout !== '_' && hnout !== '' && reBadHn.test(hnout) === false;
|
||||||
|
};
|
||||||
|
|
||||||
const isSwitchRule = ( ) => {
|
const isSwitchRule = ( ) => {
|
||||||
const token = tokens[0];
|
const token = tokens[0];
|
||||||
return token.charCodeAt(token.length-1) === 0x3A /* ':' */;
|
return token.charCodeAt(token.length-1) === 0x3A /* ':' */;
|
||||||
@ -111,7 +124,7 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
|||||||
if ( this.sortType === 0 ) { return 'sortkey'; }
|
if ( this.sortType === 0 ) { return 'sortkey'; }
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if ( reIsNotHostname.test(token) && token !== '*' ) {
|
if ( isValidHostname(token) === false ) {
|
||||||
return skipToEnd(stream, 'error');
|
return skipToEnd(stream, 'error');
|
||||||
}
|
}
|
||||||
if ( this.sortType === 1 ) { return 'sortkey'; }
|
if ( this.sortType === 1 ) { return 'sortkey'; }
|
||||||
@ -120,14 +133,13 @@ CodeMirror.defineMode('ubo-dynamic-filtering', ( ) => {
|
|||||||
// Field 2: hostname or url
|
// Field 2: hostname or url
|
||||||
if ( tokenIndex === 2 ) {
|
if ( tokenIndex === 2 ) {
|
||||||
if ( isSwitchRule(tokens[0]) ) {
|
if ( isSwitchRule(tokens[0]) ) {
|
||||||
if ( reIsNotHostname.test(token) && token !== '*' ) {
|
if ( isValidHostname(token) === false ) {
|
||||||
return skipToEnd(stream, 'error');
|
return skipToEnd(stream, 'error');
|
||||||
}
|
}
|
||||||
if ( this.sortType === 1 ) { return 'sortkey'; }
|
if ( this.sortType === 1 ) { return 'sortkey'; }
|
||||||
}
|
}
|
||||||
if (
|
if (
|
||||||
reIsNotHostname.test(token) &&
|
isValidHostname(token) === false &&
|
||||||
token !== '*' &&
|
|
||||||
isURLRule(token) === false
|
isURLRule(token) === false
|
||||||
) {
|
) {
|
||||||
return skipToEnd(stream, 'error');
|
return skipToEnd(stream, 'error');
|
||||||
|
Loading…
Reference in New Issue
Block a user