Commit fce9aaa 1 parent d9897e0 commit fce9aaa Copy full SHA for fce9aaa
File tree 1 file changed +11
-7
lines changed
1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -14,22 +14,27 @@ Zeros.fill(0);
14
14
function checkComponent ( comp : Uint8Array ) : Uint8Array {
15
15
if ( comp . length === 0 ) { throw new Error ( "invalid ENS name; empty component" ) ; }
16
16
let nonUnder = false ;
17
- let last = - 1 ;
17
+ let allAscii = true ;
18
18
for ( let i = 0 ; i < comp . length ; i ++ ) {
19
19
const c = comp [ i ] ;
20
20
21
21
// An underscore (i.e. "_"); only allows at the beginning
22
22
if ( c === 0x5f ) {
23
23
if ( nonUnder ) { throw new Error ( "invalid ENS name; non-prefix underscore" ) ; }
24
24
} else {
25
- // A hyphen (i.e. "-"); only allows a single in a row
26
- if ( c === 0x2d && last === c ) {
27
- throw new Error ( "invalid ENS name; double-hyphen" ) ;
28
- }
25
+ // Non-ASCII byte
26
+ if ( c & 0x80 ) { allAscii = false ; }
27
+
28
+ // Non-underscore found
29
29
nonUnder = true ;
30
30
}
31
- last = c ;
32
31
}
32
+
33
+ // Prevent punycode-looking components
34
+ if ( allAscii && comp [ 2 ] === 0x2d && comp [ 3 ] === 0x2d ) {
35
+ throw new Error ( "invalid ENS name; punycode conflict" ) ;
36
+ }
37
+
33
38
return comp ;
34
39
}
35
40
@@ -98,4 +103,3 @@ export function dnsEncode(name: string): string {
98
103
99
104
} ) ) ) + "00" ;
100
105
}
101
-
You can’t perform that action at this time.
0 commit comments