Skip to content

Commit e0739b7

Browse files
ayuan0828ptomato
authored andcommitted
decodeURIComponent test
1 parent b5ce1ae commit e0739b7

File tree

2 files changed

+40
-87
lines changed

2 files changed

+40
-87
lines changed

test/built-ins/decodeURI/throws-URIError.js

-87
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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

Comments
 (0)