test_bug464591.js (1342B)
1 // 1.percent-encoded IDN that contains blacklisted character should be converted 2 // to punycode, not UTF-8 string 3 // 2.only hostname-valid percent encoded ASCII characters should be decoded 4 // 3.IDN convertion must not bypassed by %00 5 6 "use strict"; 7 8 let reference = [ 9 [ 10 "www.example.com%e2%88%95www.mozill%d0%b0.com%e2%81%84www.mozilla.org", 11 "www.example.xn--comwww-re3c.xn--mozill-8nf.xn--comwww-rq0c.mozilla.org", 12 ], 13 ]; 14 15 let badURIs = [ 16 ["www.mozill%61%2f.org"], // a slash is not valid in the hostname 17 ["www.e%00xample.com%e2%88%95www.mozill%d0%b0.com%e2%81%84www.mozill%61.org"], 18 ]; 19 20 function stringToURL(str) { 21 return Cc["@mozilla.org/network/standard-url-mutator;1"] 22 .createInstance(Ci.nsIStandardURLMutator) 23 .init(Ci.nsIStandardURL.URLTYPE_AUTHORITY, 80, str, "UTF-8", null) 24 .finalize() 25 .QueryInterface(Ci.nsIURL); 26 } 27 28 function run_test() { 29 for (let i = 0; i < reference.length; ++i) { 30 try { 31 let result = stringToURL("http://" + reference[i][0]).host; 32 equal(result, reference[i][1]); 33 } catch (e) { 34 ok(false, "Error testing " + reference[i][0]); 35 } 36 } 37 38 for (let i = 0; i < badURIs.length; ++i) { 39 Assert.throws( 40 () => { 41 stringToURL("http://" + badURIs[i][0]).host; 42 }, 43 /NS_ERROR_MALFORMED_URI/, 44 "bad escaped character" 45 ); 46 } 47 }