1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-02 17:02:40 +01:00

Minor code review

This commit is contained in:
Raymond Hill 2023-01-30 11:11:56 -05:00
parent c36f674789
commit c54b521345
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -1169,10 +1169,6 @@ export class AstFilterParser {
this.isAdblockHostnamePattern(pattern) this.isAdblockHostnamePattern(pattern)
) { ) {
this.astTypeFlavor = AST_TYPE_NETWORK_PATTERN_HOSTNAME; this.astTypeFlavor = AST_TYPE_NETWORK_PATTERN_HOSTNAME;
pattern = pattern.slice(2, -1);
const normal = this.hasUnicode
? this.normalizeHostnameValue(pattern)
: pattern;
this.addFlags( this.addFlags(
AST_FLAG_NET_PATTERN_LEFT_HNANCHOR | AST_FLAG_NET_PATTERN_LEFT_HNANCHOR |
AST_FLAG_NET_PATTERN_RIGHT_PATHANCHOR AST_FLAG_NET_PATTERN_RIGHT_PATHANCHOR
@ -1188,10 +1184,14 @@ export class AstFilterParser {
parentBeg + 2, parentBeg + 2,
parentEnd - 1 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 ) { if ( normal !== undefined && normal !== pattern ) {
this.setNodeTransform(next, normal); this.setNodeTransform(next, normal);
} }
this.addNodeToRegister(NODE_TYPE_NET_PATTERN, next);
prev = this.linkRight(prev, next); prev = this.linkRight(prev, next);
next = this.allocTypedNode( next = this.allocTypedNode(
NODE_TYPE_NET_PATTERN_PART_SPECIAL, NODE_TYPE_NET_PATTERN_PART_SPECIAL,
@ -2277,6 +2277,11 @@ export class AstFilterParser {
// 0b00100: can use single wildcard // 0b00100: can use single wildcard
// 0b01000: can be negated // 0b01000: can be negated
// 0b10000: can be a regex // 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) { normalizeHostnameValue(s, modeBits = 0b00000) {
if ( this.reHostnameAscii.test(s) ) { return; } if ( this.reHostnameAscii.test(s) ) { return; }
if ( this.reBadHostnameChars.test(s) ) { return ''; } if ( this.reBadHostnameChars.test(s) ) { return ''; }