1425bb815Sopenharmony_ci// Copyright JS Foundation and other contributors, http://js.foundation 2425bb815Sopenharmony_ci// 3425bb815Sopenharmony_ci// Licensed under the Apache License, Version 2.0 (the "License"); 4425bb815Sopenharmony_ci// you may not use this file except in compliance with the License. 5425bb815Sopenharmony_ci// You may obtain a copy of the License at 6425bb815Sopenharmony_ci// 7425bb815Sopenharmony_ci// http://www.apache.org/licenses/LICENSE-2.0 8425bb815Sopenharmony_ci// 9425bb815Sopenharmony_ci// Unless required by applicable law or agreed to in writing, software 10425bb815Sopenharmony_ci// distributed under the License is distributed on an "AS IS" BASIS 11425bb815Sopenharmony_ci// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12425bb815Sopenharmony_ci// See the License for the specific language governing permissions and 13425bb815Sopenharmony_ci// limitations under the License. 14425bb815Sopenharmony_ci 15425bb815Sopenharmony_ci// URI encoding 16425bb815Sopenharmony_ci 17425bb815Sopenharmony_ci// This test will not pass on FLOAT32 due to precision issues 18425bb815Sopenharmony_ci 19425bb815Sopenharmony_cifunction checkEncodeURIParseError (str) 20425bb815Sopenharmony_ci{ 21425bb815Sopenharmony_ci try { 22425bb815Sopenharmony_ci encodeURI (str); 23425bb815Sopenharmony_ci assert (false); 24425bb815Sopenharmony_ci } catch(e) { 25425bb815Sopenharmony_ci assert(e instanceof URIError); 26425bb815Sopenharmony_ci } 27425bb815Sopenharmony_ci} 28425bb815Sopenharmony_ci 29425bb815Sopenharmony_ciassert (encodeURI ("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f") === 30425bb815Sopenharmony_ci "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F"); 31425bb815Sopenharmony_ciassert (encodeURI ("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") === 32425bb815Sopenharmony_ci "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F"); 33425bb815Sopenharmony_ciassert (encodeURI (" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN") === 34425bb815Sopenharmony_ci "%20!%22#$%25&'()*+,-./0123456789:;%3C=%3E?@ABCDEFGHIJKLMN"); 35425bb815Sopenharmony_ciassert (encodeURI ("OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\x7F") === 36425bb815Sopenharmony_ci "OPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7F"); 37425bb815Sopenharmony_ci 38425bb815Sopenharmony_ciassert (encodeURIComponent ("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f") === 39425bb815Sopenharmony_ci "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F"); 40425bb815Sopenharmony_ciassert (encodeURIComponent ("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") === 41425bb815Sopenharmony_ci "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F"); 42425bb815Sopenharmony_ciassert (encodeURIComponent (" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN") === 43425bb815Sopenharmony_ci "%20!%22%23%24%25%26'()*%2B%2C-.%2F0123456789%3A%3B%3C%3D%3E%3F%40ABCDEFGHIJKLMN"); 44425bb815Sopenharmony_ciassert (encodeURIComponent ("OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\x7F") === 45425bb815Sopenharmony_ci "OPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7F"); 46425bb815Sopenharmony_ci 47425bb815Sopenharmony_ciassert (encodeURI ("\xe9") == "%C3%A9"); 48425bb815Sopenharmony_ciassert (encodeURI ("\ud7ff") == "%ED%9F%BF"); 49425bb815Sopenharmony_ciassert (encodeURI ("\ue000") == "%EE%80%80"); 50425bb815Sopenharmony_ciassert (encodeURI ("\ud800\udc00") == "%F0%90%80%80"); 51425bb815Sopenharmony_ciassert (encodeURI (String.fromCharCode(0xd800, 0xdc00)) == "%F0%90%80%80"); 52425bb815Sopenharmony_ci 53425bb815Sopenharmony_cicheckEncodeURIParseError ("\ud800"); 54425bb815Sopenharmony_cicheckEncodeURIParseError ("\udfff"); 55425bb815Sopenharmony_ci 56425bb815Sopenharmony_ci// URI decoding 57425bb815Sopenharmony_ci 58425bb815Sopenharmony_cifunction checkDecodeURIParseError (str) 59425bb815Sopenharmony_ci{ 60425bb815Sopenharmony_ci try { 61425bb815Sopenharmony_ci decodeURI (str); 62425bb815Sopenharmony_ci assert (false); 63425bb815Sopenharmony_ci } catch(e) { 64425bb815Sopenharmony_ci assert(e instanceof URIError); 65425bb815Sopenharmony_ci } 66425bb815Sopenharmony_ci} 67425bb815Sopenharmony_ci 68425bb815Sopenharmony_ciassert (decodeURI ("%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F") === 69425bb815Sopenharmony_ci "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"); 70425bb815Sopenharmony_ciassert (decodeURI ("%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F") === 71425bb815Sopenharmony_ci "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"); 72425bb815Sopenharmony_ciassert (decodeURI ("%20%21%22%23%24%25%26%27%28%29%2a%2b%2c%2d%2e%2f") === 73425bb815Sopenharmony_ci " !\"%23%24%%26'()*%2b%2c-.%2f"); 74425bb815Sopenharmony_ciassert (decodeURI ("%30%31%32%33%34%35%36%37%38%39%3a%3b%3c%3d%3e%3f") === 75425bb815Sopenharmony_ci "0123456789%3a%3b<%3d>%3f"); 76425bb815Sopenharmony_ciassert (decodeURI ("%40%41%42%43%44%45%46%47%48%49%4a%4b%4c%4d%4e%4f") === 77425bb815Sopenharmony_ci "%40ABCDEFGHIJKLMNO"); 78425bb815Sopenharmony_ciassert (decodeURI ("%50%51%52%53%54%55%56%57%58%59%5a%5b%5c%5d%5e%5f") === 79425bb815Sopenharmony_ci "PQRSTUVWXYZ[\\]^_"); 80425bb815Sopenharmony_ciassert (decodeURI ("%60%61%62%63%64%65%66%67%68%69%6a%6b%6c%6d%6e%6f") === 81425bb815Sopenharmony_ci "`abcdefghijklmno"); 82425bb815Sopenharmony_ciassert (decodeURI ("%70%71%72%73%74%75%76%77%78%79%7a%7b%7c%7d%7e") === 83425bb815Sopenharmony_ci "pqrstuvwxyz{|}~"); 84425bb815Sopenharmony_ci 85425bb815Sopenharmony_ciassert (decodeURIComponent ("%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F") === 86425bb815Sopenharmony_ci "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"); 87425bb815Sopenharmony_ciassert (decodeURIComponent ("%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F") === 88425bb815Sopenharmony_ci "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"); 89425bb815Sopenharmony_ciassert (decodeURIComponent ("%20%21%22%23%24%25%26%27%28%29%2a%2b%2c%2d%2e%2f") === 90425bb815Sopenharmony_ci " !\"#$%&'()*+,-./"); 91425bb815Sopenharmony_ciassert (decodeURIComponent ("%30%31%32%33%34%35%36%37%38%39%3a%3b%3c%3d%3e%3f") === 92425bb815Sopenharmony_ci "0123456789:;<=>?"); 93425bb815Sopenharmony_ciassert (decodeURIComponent ("%40%41%42%43%44%45%46%47%48%49%4a%4b%4c%4d%4e%4f") === 94425bb815Sopenharmony_ci "@ABCDEFGHIJKLMNO"); 95425bb815Sopenharmony_ciassert (decodeURIComponent ("%50%51%52%53%54%55%56%57%58%59%5a%5b%5c%5d%5e%5f") === 96425bb815Sopenharmony_ci "PQRSTUVWXYZ[\\]^_"); 97425bb815Sopenharmony_ciassert (decodeURIComponent ("%60%61%62%63%64%65%66%67%68%69%6a%6b%6c%6d%6e%6f") === 98425bb815Sopenharmony_ci "`abcdefghijklmno"); 99425bb815Sopenharmony_ciassert (decodeURIComponent ("%70%71%72%73%74%75%76%77%78%79%7a%7b%7c%7d%7e") === 100425bb815Sopenharmony_ci "pqrstuvwxyz{|}~"); 101425bb815Sopenharmony_ci 102425bb815Sopenharmony_ciassert (decodeURI ("%6A%6B%6C%6D%6E%6F") === "jklmno"); 103425bb815Sopenharmony_ciassert (decodeURI ("%C3%A9") === "\xe9"); 104425bb815Sopenharmony_ciassert (decodeURI ("%e2%b1%a5") === "\u2c65"); 105425bb815Sopenharmony_ciassert (decodeURI ("%f0%90%90%a8") === "\ud801\udc28"); 106425bb815Sopenharmony_ci 107425bb815Sopenharmony_cicheckDecodeURIParseError ("13%"); 108425bb815Sopenharmony_cicheckDecodeURIParseError ("%0g"); 109425bb815Sopenharmony_cicheckDecodeURIParseError ("%1G"); 110425bb815Sopenharmony_cicheckDecodeURIParseError ("%a"); 111425bb815Sopenharmony_cicheckDecodeURIParseError ("%c1%81"); 112425bb815Sopenharmony_cicheckDecodeURIParseError ("a%80b"); 113425bb815Sopenharmony_cicheckDecodeURIParseError ("%f4%90%80%80"); 114425bb815Sopenharmony_cicheckDecodeURIParseError ("%ed%a0%80"); 115425bb815Sopenharmony_cicheckDecodeURIParseError ("%ed%b0%80"); 116425bb815Sopenharmony_cicheckDecodeURIParseError ("%fa%81%82%83%84"); 117425bb815Sopenharmony_cicheckDecodeURIParseError ("%fd%81%82%83%84%85"); 118425bb815Sopenharmony_ci 119425bb815Sopenharmony_ci// Coerce (automatic toString()) tests 120425bb815Sopenharmony_ci 121425bb815Sopenharmony_ciassert (decodeURI ([1, 2, 3]) === "1,2,3"); 122425bb815Sopenharmony_ciassert (decodeURI ({ x:1 }) === "[object Object]"); 123425bb815Sopenharmony_ciassert (encodeURI (void 0) === "undefined"); 124425bb815Sopenharmony_ciassert (encodeURI (216.000e1) === "2160"); 125425bb815Sopenharmony_ci 126425bb815Sopenharmony_ci// Combining surrogate fragments 127425bb815Sopenharmony_ci 128425bb815Sopenharmony_ciassert (decodeURI("\ud800\udc00 \ud800 \udc00") === "\ud800\udc00 \ud800 \udc00"); 129425bb815Sopenharmony_ciassert (decodeURI("%f0%90%80%80") === "\ud800\udc00"); 130425bb815Sopenharmony_ciassert (decodeURI("\ud800%f0%90%80%80\ud800") === "\ud800\ud800\udc00\ud800"); 131425bb815Sopenharmony_ciassert (decodeURI("\udc00%f0%90%80%80\udc00") === "\udc00\ud800\udc00\udc00"); 132425bb815Sopenharmony_ci 133425bb815Sopenharmony_cicheckDecodeURIParseError ("\ud800%ed%b0%80"); 134425bb815Sopenharmony_cicheckDecodeURIParseError ("%ed%a0%80\udc00"); 135