Fix syntax highlighter throwing with invalid patterns

The syntax highlighter could throw with some invalid static
network filter patterns. This was caused by the syntax
highlighter still drilling down the pattern parts after
having told codemirror to style the whole pattern as an
error, thus causing the codemirror stream position to go
backward.
This commit is contained in:
Raymond Hill 2023-06-28 08:38:47 -04:00
parent ea6e2540fd
commit 8b7a5264de
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2
1 changed files with 11 additions and 5 deletions

View File

@ -59,16 +59,20 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
let lastNetOptionType = 0;
const redirectTokenStyle = node => {
const rawToken = astParser.getNodeString(node);
const rawToken = astParser.getNodeString(node || currentWalkerNode);
const { token } = sfp.parseRedirectValue(rawToken);
return redirectNames.has(token) ? 'value' : 'value warning';
};
const nodeHasError = node => {
return astParser.getNodeFlags(
node || currentWalkerNode, sfp.NODE_FLAG_ERROR
) !== 0;
};
const colorFromAstNode = function() {
if ( astParser.nodeIsEmptyString(currentWalkerNode) ) { return '+'; }
if ( astParser.getNodeFlags(currentWalkerNode, sfp.NODE_FLAG_ERROR) !== 0 ) {
return 'error';
}
if ( nodeHasError() ) { return 'error'; }
const nodeType = astParser.getNodeType(currentWalkerNode);
switch ( nodeType ) {
case sfp.NODE_TYPE_WHITESPACE:
@ -199,7 +203,7 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
switch ( lastNetOptionType ) {
case sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECT:
case sfp.NODE_TYPE_NET_OPTION_NAME_REDIRECTRULE:
return redirectTokenStyle(currentWalkerNode);
return redirectTokenStyle();
default:
break;
}
@ -234,6 +238,8 @@ CodeMirror.defineMode('ubo-static-filtering', function() {
return 'comment';
}
currentWalkerNode = astWalker.reset();
} else if ( nodeHasError() ) {
currentWalkerNode = astWalker.right();
} else {
currentWalkerNode = astWalker.next();
}