diff --git a/test/built-ins/decodeURI/throws-URIError.js b/test/built-ins/decodeURI/throws-URIError.js deleted file mode 100644 index 54d3288dc8..0000000000 --- a/test/built-ins/decodeURI/throws-URIError.js +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (C) 2025 ayuan. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -info: | - Verify decodeURIComponent throws URIError for various invalid UTF-8 sequences - Reference: https://stackoverflow.com/a/1319229/172999 -esid: sec-decodeuricomponent-encodeduricomponent -description: | - Invalid sequences include: - - Surrogate pair encoding - - Overlong encoding - - Invalid continuation bytes - - Incomplete sequences - - Out-of-range code points -features: [uricode] ----*/ - -// CHECK#1: Reserved surrogate pair (U+D800-DFFF) -(function CHECK1() { - var result = true; - try { - decodeURIComponent('%ED%BF%BF'); - result = false; - } catch (e) { - if (!(e instanceof URIError)) result = false; - } - if (!result) { - throw new Test262Error('#1: %ED%BF%BF (surrogate pair) should throw URIError'); - } -})(); - -// CHECK#2: Overlong encoding for ASCII character -(function CHECK2() { - var result = true; - try { - decodeURIComponent('%C0%AF'); - result = false; - } catch (e) { - if (!(e instanceof URIError)) result = false; - } - if (!result) { - throw new Test262Error('#2: %C0%AF (overlong encoding) should throw URIError'); - } -})(); - -// CHECK#3: Invalid continuation byte pattern -(function CHECK3() { - var result = true; - try { - decodeURIComponent('%ED%7F%BF'); - result = false; - } catch (e) { - if (!(e instanceof URIError)) result = false; - } - if (!result) { - throw new Test262Error('#3: %ED%7F%BF (invalid continuation) should throw URIError'); - } -})(); - -// CHECK#4: Incomplete 3-byte sequence -(function CHECK4() { - var result = true; - try { - decodeURIComponent('%ED%BF'); - result = false; - } catch (e) { - if (!(e instanceof URIError)) result = false; - } - if (!result) { - throw new Test262Error('#4: %ED%BF (incomplete sequence) should throw URIError'); - } -})(); - -// CHECK#5: Code point beyond U+10FFFF -(function CHECK5() { - var result = true; - try { - decodeURIComponent('%F4%90%80%80'); - result = false; - } catch (e) { - if (!(e instanceof URIError)) result = false; - } - if (!result) { - throw new Test262Error('#5: %F4%90%80%80 (out-of-range) should throw URIError'); - } -})(); \ No newline at end of file diff --git a/test/built-ins/decodeURIComponent/throw-URIError.js b/test/built-ins/decodeURIComponent/throw-URIError.js new file mode 100644 index 0000000000..d977be28b7 --- /dev/null +++ b/test/built-ins/decodeURIComponent/throw-URIError.js @@ -0,0 +1,40 @@ +// Copyright (C) 2025 ayuan. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: Verify decodeURIComponent throws URIError for various invalid UTF-8 sequences +esid: sec-decodeuricomponent-encodeduricomponent +info: | + Invalid sequences include: + - Surrogate pair encoding + - Overlong encoding + - Invalid continuation bytes + - Incomplete sequences + - Out-of-range code points + Reference: https://stackoverflow.com/a/1319229/172999 +---*/ + +// CHECK#1: Reserved surrogate pair (U+D800-DFFF) +assert.throws(URIError, function CHECK1() { + decodeURIComponent('%ED%BF%BF'); +}, '#1: %ED%BF%BF (surrogate pair) should throw URIError'); + +// CHECK#2: Overlong encoding for ASCII character +assert.throws(URIError, function CHECK2() { + decodeURIComponent('%C0%AF'); +}, '#2: %C0%AF (overlong encoding) should throw URIError'); + +// CHECK#3: Invalid continuation byte pattern +assert.throws(URIError, function CHECK3() { + decodeURIComponent('%ED%7F%BF'); +}, '#3: %ED%7F%BF (invalid continuation) should throw URIError'); + +// CHECK#4: Incomplete 3-byte sequence +assert.throws(URIError, function CHECK4() { + decodeURIComponent('%ED%BF'); +}, '#4: %ED%BF (incomplete sequence) should throw URIError'); + +// CHECK#5: Code point beyond U+10FFFF +assert.throws(URIError, function CHECK5() { + decodeURIComponent('%F4%90%80%80'); +},'#5: %F4%90%80%80 (out-of-range) should throw URIError'); \ No newline at end of file