1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 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 16/* 17 * @tc.name:decodeuricomponent 18 * @tc.desc:test decodeuricomponent 19 * @tc.type: FUNC 20 * @tc.require: issueI7CTF7 21 */ 22let uri="%c2%aa%66%55%58%c2%83%c2%93%00%c2%89%c3%96%08%58%c2%b4%c3%bd%46"; 23let uri_encode=decodeURIComponent(uri); 24print(encodeURIComponent(uri_encode)); 25 26let uri1="%00"; 27let uri_encode1=decodeURIComponent(uri1); 28print(encodeURIComponent(uri_encode1)); 29 30try { 31 let invalidURI = "%c0%80"; 32 decodeURIComponent(invalidURI); 33} catch(err) { 34 print(err.name); 35} 36 37try { 38 let invalidURI1 = "http://example.com/?q=%"; 39 decodeURI(invalidURI1); 40} catch(err) { 41 print(err); 42} 43 44try { 45 let invalidURI2 = "%E4%25BD%2593%25E8%2582%25B2"; 46 decodeURIComponent(invalidURI2); 47} catch(err) { 48 print(err); 49} 50 51let header = "https://ifs.tanx.com/display_ifs?i~"; 52try { 53 let invalidURI = header + "%F5%8F%BF%BF"; 54 decodeURIComponent(invalidURI); 55} catch (err) { 56 print(err.name); 57} 58 59try { 60 let invalidURI = header + "%F4%90%BF%BF"; 61 decodeURIComponent(invalidURI); 62} catch (err) { 63 print(err.name); 64} 65 66{ 67 let validURI = header + "%F4%8F%BF%BF"; 68 decodeURIComponent(validURI); 69 print("decode successful"); 70} 71 72var uri0="https://www.runoob.com/my t" + "est.php?name=ståle&car=saab"; 73var uri11 = uri0 + "/jfdlskafasfd"; 74var uri2 = uri0 + "/2389018203"; 75var uri3 = uri11 + "/jd2931dsafdsa"; 76var uri4 = uri3 + "/jd2931wjeiojfwre"; 77print(encodeURIComponent(uri0)); 78print(encodeURIComponent(uri11)); 79print(encodeURIComponent(uri2)); 80print(encodeURIComponent(uri3)); 81print(encodeURIComponent(uri4)); 82 83print(decodeURIComponent(uri0)); 84print(decodeURIComponent(uri11)); 85print(decodeURIComponent(uri2)); 86print(decodeURIComponent(uri3)); 87print(decodeURIComponent(uri4)); 88 89{ 90 var result = true; 91 var arr = [ 92 [0x00, 0x2F], 93 [0x47, 0x60], 94 ]; 95 for (var i = 0; i < arr.length; i++) { 96 for (var j = arr[i][0]; j <= arr[i][1]; j++) { 97 try { 98 decodeURIComponent("%" + String.fromCharCode(j)+ "1"); 99 decodeURIComponent("%" + "1" + String.fromCharCode(j)); 100 decodeURIComponent("%C0%" + String.fromCharCode(j, j)); 101 decodeURIComponent("%E0%" + String.fromCharCode(j, j) + "%A0"); 102 decodeURIComponent("%E0" + "%A0%" + String.fromCharCode(j, j)); 103 decodeURIComponent("%F0%" + String.fromCharCode(j, j) + "%A0%A0"); 104 decodeURIComponent("%F0" + "%A0%" + String.fromCharCode(j, j) + "%A0"); 105 decodeURIComponent("%F0" + "%A0%A0%" + String.fromCharCode(j, j)); 106 result = false; 107 } catch (e) { 108 if ((e instanceof URIError) !== true) { 109 result = false; 110 } 111 } 112 } 113 } 114 print(result) 115} 116 117let invalid_uri_list = ["%ED%A0%80", "%ED%AF%BF", "%ED%B0%80", "%ED%BF%BF", "%E0%9F%BF"] 118for (let i = 0; i < invalid_uri_list.length; ++i) { 119 try { 120 decodeURIComponent(invalid_uri_list[i]); 121 } catch (err) { 122 print(err.name) 123 } 124}