From c54b5213457755d0653b0d219f9cb5fabcbcafd4 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 30 Jan 2023 11:11:56 -0500 Subject: [PATCH] Minor code review --- src/js/static-filtering-parser.js | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/js/static-filtering-parser.js b/src/js/static-filtering-parser.js index dbd778daa..9581e6ac9 100644 --- a/src/js/static-filtering-parser.js +++ b/src/js/static-filtering-parser.js @@ -1169,10 +1169,6 @@ export class AstFilterParser { this.isAdblockHostnamePattern(pattern) ) { this.astTypeFlavor = AST_TYPE_NETWORK_PATTERN_HOSTNAME; - pattern = pattern.slice(2, -1); - const normal = this.hasUnicode - ? this.normalizeHostnameValue(pattern) - : pattern; this.addFlags( AST_FLAG_NET_PATTERN_LEFT_HNANCHOR | AST_FLAG_NET_PATTERN_RIGHT_PATHANCHOR @@ -1188,10 +1184,14 @@ export class AstFilterParser { parentBeg + 2, parentEnd - 1 ); - this.addNodeToRegister(NODE_TYPE_NET_PATTERN, next); + pattern = pattern.slice(2, -1); + const normal = this.hasUnicode + ? this.normalizeHostnameValue(pattern) + : pattern; if ( normal !== undefined && normal !== pattern ) { this.setNodeTransform(next, normal); } + this.addNodeToRegister(NODE_TYPE_NET_PATTERN, next); prev = this.linkRight(prev, next); next = this.allocTypedNode( NODE_TYPE_NET_PATTERN_PART_SPECIAL, @@ -2277,6 +2277,11 @@ export class AstFilterParser { // 0b00100: can use single wildcard // 0b01000: can be negated // 0b10000: can be a regex + // + // returns: + // undefined: no normalization needed, use original hostname + // empty string: hostname is invalid + // non-empty string: normalized hostname normalizeHostnameValue(s, modeBits = 0b00000) { if ( this.reHostnameAscii.test(s) ) { return; } if ( this.reBadHostnameChars.test(s) ) { return ''; }