| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- var isNode = (typeof module !== 'undefined' && module.exports);
- if (isNode) {
- var SanityTest = require(__dirname + '/../../test/sanitytest');
- }
- var Urlencoded = {
- detect: function(str) {
-
-
- 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) {
-
- 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;
- }
|