@@ -90,6 +90,11 @@ export const AST_FLAG_NET_PATTERN_LEFT_ANCHOR = 1 << iota++;
9090export const AST_FLAG_NET_PATTERN_RIGHT_ANCHOR = 1 << iota ++ ;
9191export const AST_FLAG_HAS_OPTIONS = 1 << iota ++ ;
9292
93+ iota = 0 ;
94+ export const AST_ERROR_NONE = 1 << iota ++ ;
95+ export const AST_ERROR_BAD_REGEX = 1 << iota ++ ;
96+ export const AST_ERROR_BAD_PATTERN = 1 << iota ++ ;
97+
9398iota = 0 ;
9499const NODE_RIGHT_INDEX = iota ++ ;
95100const NOOP_NODE_SIZE = iota ;
@@ -736,7 +741,7 @@ export class AstFilterParser {
736741 this . reHasWhitespaceChar = / \s / ;
737742 this . reHasUppercaseChar = / [ A - Z ] / ;
738743 this . reHasUnicodeChar = / [ ^ \x00 - \x7F ] / ;
739- this . reUnicodeChars = / [ ^ \x00 - \x7F ] / g ;
744+ this . reUnicodeChars = / \P { ASCII } / gu ;
740745 this . reBadHostnameChars = / [ \x00 - \x24 \x26 - \x29 \x2b \x2c \x2f \x3b - \x40 \x5c \x5e \x60 \x7b - \x7f ] / ;
741746 this . reIsEntity = / ^ [ ^ * ] + \. \* $ / ;
742747 this . rePreparseDirectiveIf = / ^ ! # i f / ;
@@ -765,6 +770,7 @@ export class AstFilterParser {
765770 this . astType = AST_TYPE_NONE ;
766771 this . astTypeFlavor = AST_TYPE_NONE ;
767772 this . astFlags = 0 ;
773+ this . astError = 0 ;
768774 this . rootNode = this . allocTypedNode ( NODE_TYPE_LINE_RAW , 0 , this . rawEnd ) ;
769775 if ( this . rawEnd === 0 ) { return ; }
770776
@@ -1475,6 +1481,7 @@ export class AstFilterParser {
14751481 }
14761482 } else {
14771483 this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_BAD ;
1484+ this . astError = AST_ERROR_BAD_REGEX ;
14781485 this . addFlags ( AST_FLAG_HAS_ERROR ) ;
14791486 this . addNodeFlags ( next , NODE_FLAG_ERROR ) ;
14801487 }
@@ -1592,18 +1599,19 @@ export class AstFilterParser {
15921599 ? this . normalizePattern ( pattern )
15931600 : pattern ;
15941601 next = this . allocTypedNode ( NODE_TYPE_NET_PATTERN , patternBeg , patternEnd ) ;
1595- if ( normal === '' || pattern === '*' ) {
1602+ if ( normal === undefined ) {
1603+ this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_BAD ;
1604+ this . addFlags ( AST_FLAG_HAS_ERROR ) ;
1605+ this . astError = AST_ERROR_BAD_PATTERN ;
1606+ this . addNodeFlags ( next , NODE_FLAG_ERROR ) ;
1607+ } else if ( normal === '' || pattern === '*' ) {
15961608 this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_ANY ;
15971609 } else if ( this . reHostnameAscii . test ( normal ) ) {
15981610 this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_HOSTNAME ;
15991611 } else if ( this . reHasPatternSpecialChars . test ( normal ) ) {
16001612 this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_GENERIC ;
1601- } else if ( normal !== undefined ) {
1602- this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_PLAIN ;
16031613 } else {
1604- this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_BAD ;
1605- this . addFlags ( AST_FLAG_HAS_ERROR ) ;
1606- this . addNodeFlags ( next , NODE_FLAG_ERROR ) ;
1614+ this . astTypeFlavor = AST_TYPE_NETWORK_PATTERN_PLAIN ;
16071615 }
16081616 this . addNodeToRegister ( NODE_TYPE_NET_PATTERN , next ) ;
16091617 if ( needNormalization && normal !== undefined ) {
@@ -1692,9 +1700,8 @@ export class AstFilterParser {
16921700 if ( this . reHasUnicodeChar . test ( normal ) === false ) { return normal ; }
16931701 // Percent-encode remaining Unicode characters.
16941702 try {
1695- normal = normal . replace (
1696- this . reUnicodeChars ,
1697- s => encodeURIComponent ( s ) . toLowerCase ( )
1703+ normal = normal . replace ( this . reUnicodeChars , s =>
1704+ encodeURIComponent ( s ) . toLowerCase ( )
16981705 ) ;
16991706 } catch ( ex ) {
17001707 return ;
0 commit comments