diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /devtools/shared/jsbeautify/lib/urlencode_unpacker.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'devtools/shared/jsbeautify/lib/urlencode_unpacker.js')
-rw-r--r-- | devtools/shared/jsbeautify/lib/urlencode_unpacker.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/devtools/shared/jsbeautify/lib/urlencode_unpacker.js b/devtools/shared/jsbeautify/lib/urlencode_unpacker.js new file mode 100644 index 000000000..b45cd15c0 --- /dev/null +++ b/devtools/shared/jsbeautify/lib/urlencode_unpacker.js @@ -0,0 +1,73 @@ +/*global unescape */ +/*jshint curly: false, scripturl: true */ +// +// trivial bookmarklet/escaped script detector for the javascript beautifier +// written by Einar Lielmanis <einar@jsbeautifier.org> +// +// usage: +// +// if (Urlencoded.detect(some_string)) { +// var unpacked = Urlencoded.unpack(some_string); +// } +// +// + +var isNode = (typeof module !== 'undefined' && module.exports); +if (isNode) { + var SanityTest = require("devtools/shared/jsbeautify/lib/sanitytest"); +} + +var Urlencoded = { + detect: function (str) { + // the fact that script doesn't contain any space, but has %20 instead + // should be sufficient check for now. + if (str.indexOf(' ') == -1) { + if (str.indexOf('%2') != -1) return true; + if (str.replace(/[^%]+/g, '').length > 3) return true; + } + return false; + }, + + unpack: function (str) { + if (Urlencoded.detect(str)) { + if (str.indexOf('%2B') != -1 || str.indexOf('%2b') != -1) { + // "+" escaped as "%2B" + return unescape(str.replace(/\+/g, '%20')); + } else { + return unescape(str); + } + } + return str; + }, + + + + run_tests: function (sanity_test) { + var t = sanity_test || new SanityTest(); + t.test_function(Urlencoded.detect, "Urlencoded.detect"); + t.expect('', false); + t.expect('var a = b', false); + t.expect('var%20a+=+b', true); + t.expect('var%20a=b', true); + t.expect('var%20%21%22', true); + t.expect('javascript:(function(){var%20whatever={init:function(){alert(%22a%22+%22b%22)}};whatever.init()})();', true); + t.test_function(Urlencoded.unpack, 'Urlencoded.unpack'); + + t.expect('javascript:(function(){var%20whatever={init:function(){alert(%22a%22+%22b%22)}};whatever.init()})();', + 'javascript:(function(){var whatever={init:function(){alert("a"+"b")}};whatever.init()})();' + ); + t.expect('', ''); + t.expect('abcd', 'abcd'); + t.expect('var a = b', 'var a = b'); + t.expect('var%20a=b', 'var a=b'); + t.expect('var%20a=b+1', 'var a=b+1'); + t.expect('var%20a=b%2b1', 'var a=b+1'); + return t; + } + + +}; + +if (isNode) { + module.exports = Urlencoded; +} |