1
+ // Copyright (C) 2025 ayuan. All rights reserved.
2
+ // This code is governed by the BSD license found in the LICENSE file.
3
+
4
+ /*---
5
+ description: Verify decodeURIComponent throws URIError for various invalid UTF-8 sequences
6
+ esid: sec-decodeuricomponent-encodeduricomponent
7
+ info: |
8
+ Invalid sequences include:
9
+ - Surrogate pair encoding
10
+ - Overlong encoding
11
+ - Invalid continuation bytes
12
+ - Incomplete sequences
13
+ - Out-of-range code points
14
+ Reference: https://stackoverflow.com/a/1319229/172999
15
+ ---*/
16
+
17
+ // CHECK#1: Reserved surrogate pair (U+D800-DFFF)
18
+ assert . throws ( URIError , function CHECK1 ( ) {
19
+ decodeURIComponent ( '%ED%BF%BF' ) ;
20
+ } , '#1: %ED%BF%BF (surrogate pair) should throw URIError' ) ;
21
+
22
+ // CHECK#2: Overlong encoding for ASCII character
23
+ assert . throws ( URIError , function CHECK2 ( ) {
24
+ decodeURIComponent ( '%C0%AF' ) ;
25
+ } , '#2: %C0%AF (overlong encoding) should throw URIError' ) ;
26
+
27
+ // CHECK#3: Invalid continuation byte pattern
28
+ assert . throws ( URIError , function CHECK3 ( ) {
29
+ decodeURIComponent ( '%ED%7F%BF' ) ;
30
+ } , '#3: %ED%7F%BF (invalid continuation) should throw URIError' ) ;
31
+
32
+ // CHECK#4: Incomplete 3-byte sequence
33
+ assert . throws ( URIError , function CHECK4 ( ) {
34
+ decodeURIComponent ( '%ED%BF' ) ;
35
+ } , '#4: %ED%BF (incomplete sequence) should throw URIError' ) ;
36
+
37
+ // CHECK#5: Code point beyond U+10FFFF
38
+ assert . throws ( URIError , function CHECK5 ( ) {
39
+ decodeURIComponent ( '%F4%90%80%80' ) ;
40
+ } , '#5: %F4%90%80%80 (out-of-range) should throw URIError' ) ;
0 commit comments