From b5ce1ae754e482f22ba82ee202d9320504991d04 Mon Sep 17 00:00:00 2001 From: ayuan0828 <100656290+ayuan0828@users.noreply.github.com> Date: Tue, 4 Mar 2025 11:38:50 +0800 Subject: [PATCH] Create throws-URIError.js --- test/built-ins/decodeURI/throws-URIError.js | 87 +++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/built-ins/decodeURI/throws-URIError.js diff --git a/test/built-ins/decodeURI/throws-URIError.js b/test/built-ins/decodeURI/throws-URIError.js new file mode 100644 index 0000000000..54d3288dc8 --- /dev/null +++ b/test/built-ins/decodeURI/throws-URIError.js @@ -0,0 +1,87 @@ +// 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