1// Copyright JS Foundation and other contributors, http://js.foundation 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15// Escaping 16 17assert (escape ("\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f") === 18 "%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F"); 19assert (escape ("\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f") === 20 "%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F"); 21assert (escape (" !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN") === 22 "%20%21%22%23%24%25%26%27%28%29*+%2C-./0123456789%3A%3B%3C%3D%3E%3F@ABCDEFGHIJKLMN"); 23assert (escape ("OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\x7F") === 24 "OPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7F"); 25 26assert (escape("\x80\x95\xaf\xfe\xff") === "%80%95%AF%FE%FF"); 27assert (escape("\u0100\ud800\udc00") === "%u0100%uD800%uDC00"); 28 29assert (escape({}) === "%5Bobject%20Object%5D"); 30assert (escape(true) === "true"); 31 32// Unescaping 33 34assert (unescape ("%00%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F") === 35 "\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f"); 36assert (unescape("%10%11%12%13%14%15%16%17%18%19%1A%1B%1C%1D%1E%1F") === 37 "\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f"); 38assert (unescape("%20%21%22%23%24%25%26%27%28%29*+%2C-./0123456789%3A%3B%3C%3D%3E%3F@ABCDEFGHIJKLMN") === 39 " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMN"); 40assert (unescape("OPQRSTUVWXYZ%5B%5C%5D%5E_%60abcdefghijklmnopqrstuvwxyz%7B%7C%7D%7F") === 41 "OPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}\x7F"); 42assert (unescape("%80%95%AF%FE%FF") === "\x80\x95\xaf\xfe\xff"); 43assert (unescape("%ud800") === "\ud800"); 44assert (unescape("\ud800") === "\ud800"); 45assert (unescape("\ud800\udc00") === "\ud800\udc00"); 46assert (unescape("%ud800%udc00") === "\ud800\udc00"); 47assert (unescape("\ud800%udc00") === "\ud800\udc00"); 48assert (unescape("%ud800\udc00") === "\ud800\udc00"); 49 50assert (unescape({}) === "[object Object]"); 51assert (unescape(true) === "true") 52assert (unescape() === "undefined"); 53assert (unescape(1985) === "1985"); 54assert (unescape("%5#%uu") === "%5#%uu"); 55 56// Inversion 57 58var str = "\u0001\u0000\uFFFF"; 59assert (unescape(escape(str)) === str); 60