js-beautify 0.1.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitmodules +4 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +27 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +13 -0
- data/Rakefile +29 -0
- data/VERSION +1 -0
- data/bin/js-beautify +5 -0
- data/init.sh +3 -0
- data/js-beautify-copy/.gitmodules +3 -0
- data/js-beautify-copy/Makefile +71 -0
- data/js-beautify-copy/README.md +39 -0
- data/js-beautify-copy/attic/beautify-cl/beautify-cl.js +142 -0
- data/js-beautify-copy/attic/bin/beautify_js +80 -0
- data/js-beautify-copy/attic/opera-userscript/beautifier.js +1087 -0
- data/js-beautify-copy/attic/opera-userscript/make_opera_userscript.sh +42 -0
- data/js-beautify-copy/attic/qtscript/jsbeautify.cpp +121 -0
- data/js-beautify-copy/attic/qtscript/jsbeautify.pro +5 -0
- data/js-beautify-copy/attic/qtscript/jsbeautify.qrc +6 -0
- data/js-beautify-copy/attic/qtscript/readme.txt +28 -0
- data/js-beautify-copy/attic/readme.txt +2 -0
- data/js-beautify-copy/attic/unmaintained/bbedit/jsBeautify_BBED.scpt +522 -0
- data/js-beautify-copy/attic/unmaintained/c-sharp/JSBeautify.cs +801 -0
- data/js-beautify-copy/attic/v8/README.txt +40 -0
- data/js-beautify-copy/attic/v8/beautify.h +2390 -0
- data/js-beautify-copy/attic/v8/jsbeautify.cpp +215 -0
- data/js-beautify-copy/beautify-css.js +198 -0
- data/js-beautify-copy/beautify-html.js +514 -0
- data/js-beautify-copy/beautify.js +1293 -0
- data/js-beautify-copy/favicon.png +0 -0
- data/js-beautify-copy/index.html +401 -0
- data/js-beautify-copy/jquery/jquery.cookie.js +96 -0
- data/js-beautify-copy/jquery/jquery.js +167 -0
- data/js-beautify-copy/license.txt +24 -0
- data/js-beautify-copy/php/jsbeautifier.php +1599 -0
- data/js-beautify-copy/php/test.php +476 -0
- data/js-beautify-copy/python/MANIFEST.in +2 -0
- data/js-beautify-copy/python/js-beautify +7 -0
- data/js-beautify-copy/python/js-beautify-profile +16 -0
- data/js-beautify-copy/python/js-beautify-test +10 -0
- data/js-beautify-copy/python/jsbeautifier/__init__.py +1166 -0
- data/js-beautify-copy/python/jsbeautifier/tests/__init__.py +1 -0
- data/js-beautify-copy/python/jsbeautifier/tests/testindentation.py +43 -0
- data/js-beautify-copy/python/jsbeautifier/tests/testjsbeautifier.py +464 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/README.specs.mkd +25 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/__init__.py +67 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/evalbased.py +39 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/javascriptobfuscator.py +58 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/myobfuscate.py +86 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/packer.py +104 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/__init__.py +2 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-myobfuscate-input.js +1 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-myobfuscate-output.js +65 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-packer-62-input.js +1 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-packer-non62-input.js +1 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testjavascriptobfuscator.py +46 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testmyobfuscate.py +40 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testpacker.py +34 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testurlencode.py +36 -0
- data/js-beautify-copy/python/jsbeautifier/unpackers/urlencode.py +34 -0
- data/js-beautify-copy/python/setup.py +17 -0
- data/js-beautify-copy/tests/beautify-tests.js +489 -0
- data/js-beautify-copy/tests/run-tests +17 -0
- data/js-beautify-copy/tests/sanitytest.js +128 -0
- data/js-beautify-copy/unpackers/javascriptobfuscator_unpacker.js +103 -0
- data/js-beautify-copy/unpackers/myobfuscate_unpacker.js +81 -0
- data/js-beautify-copy/unpackers/p_a_c_k_e_r_unpacker.js +61 -0
- data/js-beautify-copy/unpackers/urlencode_unpacker.js +51 -0
- data/lib/js-beautify.rb +0 -0
- data/test/helper.rb +18 -0
- data/test/test_js-beautify.rb +7 -0
- data/update.sh +23 -0
- metadata +173 -0
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/js
|
2
|
+
|
3
|
+
// a little helper for testing from command line
|
4
|
+
// just run it, it will output the test results
|
5
|
+
|
6
|
+
try {
|
7
|
+
load('beautify.js');
|
8
|
+
load('tests/sanitytest.js')
|
9
|
+
load('tests/beautify-tests.js')
|
10
|
+
} catch (yada) {
|
11
|
+
load('../beautify.js');
|
12
|
+
//load('sanitytest.js')
|
13
|
+
load('beautify-tests.js')
|
14
|
+
}
|
15
|
+
|
16
|
+
print(run_beautifier_tests().results_raw())
|
17
|
+
|
@@ -0,0 +1,128 @@
|
|
1
|
+
//
|
2
|
+
// simple testing interface
|
3
|
+
// written by Einar Lielmanis, einar@jsbeautifier.org
|
4
|
+
//
|
5
|
+
// usage:
|
6
|
+
//
|
7
|
+
// var t = new SanityTest(function (x) { return x; }, 'my function');
|
8
|
+
// t.expect('input', 'output');
|
9
|
+
// t.expect('a', 'a');
|
10
|
+
// output_somewhere(t.results()); // good for <pre>, html safe-ish
|
11
|
+
// alert(t.results_raw()); // html unescaped
|
12
|
+
|
13
|
+
|
14
|
+
function SanityTest (func, test_name) {
|
15
|
+
|
16
|
+
var test_func = func || function (x) {
|
17
|
+
return x;
|
18
|
+
}
|
19
|
+
|
20
|
+
var test_name = test_name || '';
|
21
|
+
|
22
|
+
var n_failed = 0;
|
23
|
+
var n_succeeded = 0;
|
24
|
+
|
25
|
+
var failures = [];
|
26
|
+
|
27
|
+
this.test_function = function(func, name) {
|
28
|
+
test_func = func;
|
29
|
+
test_name = name || '';
|
30
|
+
}
|
31
|
+
|
32
|
+
|
33
|
+
this.expect = function(parameters, expected_value) {
|
34
|
+
// multi-parameter calls not supported (I don't need them now).
|
35
|
+
var result = test_func(parameters);
|
36
|
+
// proper array checking is a pain. i'll maybe do it later, compare strings representations instead
|
37
|
+
if ((result === expected_value) || (expected_value instanceof Array && result.join(', ') == expected_value.join(', '))) {
|
38
|
+
n_succeeded += 1;
|
39
|
+
} else {
|
40
|
+
n_failed += 1;
|
41
|
+
failures.push([test_name, parameters, expected_value, result]);
|
42
|
+
}
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
this.results_raw = function() {
|
47
|
+
var results = '';
|
48
|
+
if (n_failed === 0) {
|
49
|
+
if (n_succeeded === 0) {
|
50
|
+
results = 'No tests run.';
|
51
|
+
} else {
|
52
|
+
results = 'All ' + n_succeeded + ' tests passed.';
|
53
|
+
}
|
54
|
+
} else {
|
55
|
+
for (var i = 0 ; i < failures.length; i++) {
|
56
|
+
var f = failures[i];
|
57
|
+
if (f[0]) {
|
58
|
+
f[0] = f[0] + ' ';
|
59
|
+
}
|
60
|
+
results += '---- ' + f[0] + 'input -------\n' + this.prettyprint(f[1]) + '\n';
|
61
|
+
results += '---- ' + f[0] + 'expected ----\n' + this.prettyprint(f[2]) + '\n';
|
62
|
+
results += '---- ' + f[0] + 'output ------\n' + this.prettyprint(f[3]) + '\n\n';
|
63
|
+
|
64
|
+
}
|
65
|
+
results += n_failed + ' tests failed.\n';
|
66
|
+
}
|
67
|
+
return results;
|
68
|
+
}
|
69
|
+
|
70
|
+
|
71
|
+
this.results = function() {
|
72
|
+
return this.lazy_escape(this.results_raw());
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
this.prettyprint = function(something, quote_strings) {
|
77
|
+
var type = typeof something;
|
78
|
+
switch(type.toLowerCase()) {
|
79
|
+
case 'string':
|
80
|
+
if (quote_strings) {
|
81
|
+
return "'" + something.replace("'", "\\'") + "'";
|
82
|
+
} else {
|
83
|
+
return something;
|
84
|
+
}
|
85
|
+
case 'number':
|
86
|
+
return '' + something;
|
87
|
+
case 'boolean':
|
88
|
+
return something ? 'true' : 'false';
|
89
|
+
case 'undefined':
|
90
|
+
return 'undefined';
|
91
|
+
case 'object':
|
92
|
+
if (something instanceof Array) {
|
93
|
+
var x = [];
|
94
|
+
var expected_index = 0;
|
95
|
+
for (k in something) {
|
96
|
+
if (k == expected_index) {
|
97
|
+
x.push(this.prettyprint(something[k], true));
|
98
|
+
expected_index += 1;
|
99
|
+
} else {
|
100
|
+
x.push('\n' + k + ': ' + this.prettyprint(something[k], true));
|
101
|
+
}
|
102
|
+
}
|
103
|
+
return '[' + x.join(', ') + ']';
|
104
|
+
} else {
|
105
|
+
return 'object: ' + something;
|
106
|
+
}
|
107
|
+
default:
|
108
|
+
return type + ': ' + something;
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
this.lazy_escape = function (str) {
|
114
|
+
return str.replace(/</g, '<').replace(/\>/g, '>').replace(/\n/g, '<br />');
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
this.log = function () {
|
119
|
+
if (window.console) {
|
120
|
+
if (console.firebug) {
|
121
|
+
console.log.apply(console, Array.prototype.slice.call(arguments));
|
122
|
+
} else {
|
123
|
+
console.log.call(console, Array.prototype.slice.call(arguments));
|
124
|
+
}
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
}
|
@@ -0,0 +1,103 @@
|
|
1
|
+
//
|
2
|
+
// simple unpacker/deobfuscator for scripts messed up with javascriptobfuscator.com
|
3
|
+
// written by Einar Lielmanis <einar@jsbeautifier.org>
|
4
|
+
//
|
5
|
+
// usage:
|
6
|
+
//
|
7
|
+
// if (JavascriptObfuscator.detect(some_string)) {
|
8
|
+
// var unpacked = JavascriptObfuscator.unpack(some_string);
|
9
|
+
// }
|
10
|
+
//
|
11
|
+
//
|
12
|
+
|
13
|
+
var JavascriptObfuscator = {
|
14
|
+
detect: function (str) {
|
15
|
+
return /^var _0x[a-f0-9]+ ?\= ?\[/.test(str);
|
16
|
+
},
|
17
|
+
|
18
|
+
unpack: function (str) {
|
19
|
+
if (JavascriptObfuscator.detect(str)) {
|
20
|
+
var matches = /var (_0x[a-f\d]+) ?\= ?\[(.*?)\];/.exec(str);
|
21
|
+
if (matches) {
|
22
|
+
var var_name = matches[1];
|
23
|
+
var strings = JavascriptObfuscator._smart_split(matches[2]);
|
24
|
+
var str = str.substring(matches[0].length);
|
25
|
+
for (var k in strings) {
|
26
|
+
str = str.replace(new RegExp(var_name + '\\[' + k + '\\]', 'g'),
|
27
|
+
JavascriptObfuscator._fix_quotes(JavascriptObfuscator._unescape(strings[k])));
|
28
|
+
}
|
29
|
+
}
|
30
|
+
}
|
31
|
+
return str;
|
32
|
+
},
|
33
|
+
|
34
|
+
_fix_quotes: function(str) {
|
35
|
+
var matches = /^"(.*)"$/.exec(str);
|
36
|
+
if (matches) {
|
37
|
+
str = matches[1];
|
38
|
+
str = "'" + str.replace(/'/g, "\\'") + "'";
|
39
|
+
}
|
40
|
+
return str;
|
41
|
+
},
|
42
|
+
|
43
|
+
_smart_split: function(str) {
|
44
|
+
var strings = [];
|
45
|
+
var pos = 0;
|
46
|
+
while (pos < str.length) {
|
47
|
+
if (str.charAt(pos) == '"') {
|
48
|
+
// new word
|
49
|
+
var word = '';
|
50
|
+
pos += 1;
|
51
|
+
while (pos < str.length) {
|
52
|
+
if (str.charAt(pos) == '"') {
|
53
|
+
break;
|
54
|
+
}
|
55
|
+
if (str.charAt(pos) == '\\') {
|
56
|
+
word += '\\';
|
57
|
+
pos++;
|
58
|
+
}
|
59
|
+
word += str.charAt(pos);
|
60
|
+
pos++;
|
61
|
+
}
|
62
|
+
strings.push('"' + word + '"');
|
63
|
+
}
|
64
|
+
pos += 1;
|
65
|
+
}
|
66
|
+
return strings;
|
67
|
+
},
|
68
|
+
|
69
|
+
|
70
|
+
_unescape: function (str) {
|
71
|
+
// inefficient if used repeatedly or on small strings, but wonderful on single large chunk of text
|
72
|
+
for (var i = 32; i < 128; i++) {
|
73
|
+
str = str.replace(new RegExp('\\\\x' + i.toString(16), 'ig'), String.fromCharCode(i));
|
74
|
+
}
|
75
|
+
str = str.replace(/\\x09/g, "\t");
|
76
|
+
return str;
|
77
|
+
},
|
78
|
+
|
79
|
+
run_tests: function (sanity_test) {
|
80
|
+
var t = sanity_test || new SanityTest();
|
81
|
+
|
82
|
+
t.test_function(JavascriptObfuscator._smart_split, "JavascriptObfuscator._smart_split");
|
83
|
+
t.expect('', []);
|
84
|
+
t.expect('"a", "b"', ['"a"', '"b"']);
|
85
|
+
t.expect('"aaa","bbbb"', ['"aaa"', '"bbbb"']);
|
86
|
+
t.expect('"a", "b\\\""', ['"a"', '"b\\\""']);
|
87
|
+
t.test_function(JavascriptObfuscator._unescape, 'JavascriptObfuscator._unescape');
|
88
|
+
t.expect('\\x40', '@');
|
89
|
+
t.expect('\\x10', '\\x10');
|
90
|
+
t.expect('\\x1', '\\x1');
|
91
|
+
t.expect("\\x61\\x62\\x22\\x63\\x64", 'ab"cd');
|
92
|
+
t.test_function(JavascriptObfuscator.detect, 'JavascriptObfuscator.detect');
|
93
|
+
t.expect('', false);
|
94
|
+
t.expect('abcd', false);
|
95
|
+
t.expect('var _0xaaaa', false);
|
96
|
+
t.expect('var _0xaaaa = ["a", "b"]', true);
|
97
|
+
t.expect('var _0xaaaa=["a", "b"]', true);
|
98
|
+
t.expect('var _0x1234=["a","b"]', true);
|
99
|
+
return t;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
}
|
@@ -0,0 +1,81 @@
|
|
1
|
+
//
|
2
|
+
// simple unpacker/deobfuscator for scripts messed up with myobfuscate.com
|
3
|
+
// You really don't want to obfuscate your scripts there: they're tracking
|
4
|
+
// your unpackings, your script gets turned into something like this,
|
5
|
+
// as of 2011-04-25:
|
6
|
+
/*
|
7
|
+
|
8
|
+
var _escape = 'your_script_escaped';
|
9
|
+
var _111 = document.createElement('script');
|
10
|
+
_111.src = 'http://api.www.myobfuscate.com/?getsrc=ok' +
|
11
|
+
'&ref=' + encodeURIComponent(document.referrer) +
|
12
|
+
'&url=' + encodeURIComponent(document.URL);
|
13
|
+
var 000 = document.getElementsByTagName('head')[0];
|
14
|
+
000.appendChild(_111);
|
15
|
+
document.write(unescape(_escape));
|
16
|
+
|
17
|
+
*/
|
18
|
+
//
|
19
|
+
// written by Einar Lielmanis <einar@jsbeautifier.org>
|
20
|
+
//
|
21
|
+
// usage:
|
22
|
+
//
|
23
|
+
// if (MyObfuscate.detect(some_string)) {
|
24
|
+
// var unpacked = MyObfuscate.unpack(some_string);
|
25
|
+
// }
|
26
|
+
//
|
27
|
+
//
|
28
|
+
|
29
|
+
var MyObfuscate = {
|
30
|
+
detect: function (str) {
|
31
|
+
if (/^var _?[0O1lI]{3}\=('|\[).*\)\)\);/.test(str)) {
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
if (/^function _?[0O1lI]{3}\(_/.test(str) && /eval\(/.test(str)) {
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
return false;
|
38
|
+
},
|
39
|
+
|
40
|
+
unpack: function (str) {
|
41
|
+
if (MyObfuscate.detect(str)) {
|
42
|
+
var modified_source = str.replace(';eval(', ';unpacked_source = (');
|
43
|
+
var unpacked_source = '';
|
44
|
+
eval(modified_source);
|
45
|
+
if (unpacked_source) {
|
46
|
+
if (MyObfuscate.starts_with(unpacked_source, 'var _escape')) {
|
47
|
+
// fetch the urlencoded stuff from the script,
|
48
|
+
var matches = /'([^']*)'/.exec(unpacked_source);
|
49
|
+
var unescaped = unescape(matches[1]);
|
50
|
+
if (MyObfuscate.starts_with(unescaped, '<script>')) {
|
51
|
+
unescaped = unescaped.substr(8, unescaped.length - 8);
|
52
|
+
}
|
53
|
+
if (MyObfuscate.ends_with(unescaped, '</script>')) {
|
54
|
+
unescaped = unescaped.substr(0, unescaped.length - 9);
|
55
|
+
}
|
56
|
+
unpacked_source = unescaped;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
return unpacked_source ? "// Unpacker warning: be careful when using myobfuscate.com for your projects:\n" +
|
60
|
+
"// scripts obfuscated by the free online version may call back home.\n" +
|
61
|
+
"\n//\n" + unpacked_source : str;
|
62
|
+
}
|
63
|
+
return str;
|
64
|
+
},
|
65
|
+
|
66
|
+
starts_with: function (str, what) {
|
67
|
+
return str.substr(0, what.length) === what;
|
68
|
+
},
|
69
|
+
|
70
|
+
ends_with: function (str, what) {
|
71
|
+
return str.substr(str.length - what.length, what.length) === what;
|
72
|
+
},
|
73
|
+
|
74
|
+
run_tests: function (sanity_test) {
|
75
|
+
var t = sanity_test || new SanityTest();
|
76
|
+
|
77
|
+
return t;
|
78
|
+
}
|
79
|
+
|
80
|
+
|
81
|
+
}
|
@@ -0,0 +1,61 @@
|
|
1
|
+
//
|
2
|
+
// Unpacker for Dean Edward's p.a.c.k.e.r, a part of javascript beautifier
|
3
|
+
// written by Einar Lielmanis <einar@jsbeautifier.org>
|
4
|
+
//
|
5
|
+
// Coincidentally, it can defeat a couple of other eval-based compressors.
|
6
|
+
//
|
7
|
+
// usage:
|
8
|
+
//
|
9
|
+
// if (P_A_C_K_E_R.detect(some_string)) {
|
10
|
+
// var unpacked = P_A_C_K_E_R.unpack(some_string);
|
11
|
+
// }
|
12
|
+
//
|
13
|
+
//
|
14
|
+
|
15
|
+
var P_A_C_K_E_R = {
|
16
|
+
detect: function (str) {
|
17
|
+
return P_A_C_K_E_R._starts_with(str.toLowerCase().replace(/ +/g, ''), 'eval(function(') ||
|
18
|
+
P_A_C_K_E_R._starts_with(str.toLowerCase().replace(/ +/g, ''), 'eval((function(') ;
|
19
|
+
},
|
20
|
+
|
21
|
+
unpack: function (str) {
|
22
|
+
var unpacked_source = '';
|
23
|
+
if (P_A_C_K_E_R.detect(str)) {
|
24
|
+
try {
|
25
|
+
eval('unpacked_source = ' + str.substring(4) + ';')
|
26
|
+
if (typeof unpacked_source == 'string' && unpacked_source) {
|
27
|
+
str = unpacked_source;
|
28
|
+
}
|
29
|
+
} catch (error) {
|
30
|
+
// well, it failed. we'll just return the original, instead of crashing on user.
|
31
|
+
}
|
32
|
+
}
|
33
|
+
return str;
|
34
|
+
},
|
35
|
+
|
36
|
+
_starts_with: function (str, what) {
|
37
|
+
return str.substr(0, what.length) === what;
|
38
|
+
},
|
39
|
+
|
40
|
+
run_tests: function (sanity_test) {
|
41
|
+
var t = sanity_test || new SanityTest();
|
42
|
+
t.test_function(P_A_C_K_E_R.detect, "P_A_C_K_E_R.detect");
|
43
|
+
t.expect('', false);
|
44
|
+
t.expect('var a = b', false);
|
45
|
+
t.expect('eval(function(p,a,c,k,e,r', true);
|
46
|
+
t.expect('eval ( function(p, a, c, k, e, r', true);
|
47
|
+
t.test_function(P_A_C_K_E_R.unpack, 'P_A_C_K_E_R.unpack');
|
48
|
+
t.expect("eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 2=1',3,3,'var||a'.split('|'),0,{}))",
|
49
|
+
'var a=1');
|
50
|
+
|
51
|
+
var starts_with_a = function(what) { return P_A_C_K_E_R._starts_with(what, 'a'); }
|
52
|
+
t.test_function(starts_with_a, "P_A_C_K_E_R._starts_with(?, a)");
|
53
|
+
t.expect('abc', true);
|
54
|
+
t.expect('bcd', false);
|
55
|
+
t.expect('a', true);
|
56
|
+
t.expect('', false);
|
57
|
+
return t;
|
58
|
+
}
|
59
|
+
|
60
|
+
|
61
|
+
}
|
@@ -0,0 +1,51 @@
|
|
1
|
+
//
|
2
|
+
// trivial bookmarklet/escaped script detector for the javascript beautifier
|
3
|
+
// written by Einar Lielmanis <einar@jsbeautifier.org>
|
4
|
+
//
|
5
|
+
// usage:
|
6
|
+
//
|
7
|
+
// if (Urlencoded.detect(some_string)) {
|
8
|
+
// var unpacked = Urlencoded.unpack(some_string);
|
9
|
+
// }
|
10
|
+
//
|
11
|
+
//
|
12
|
+
|
13
|
+
var Urlencoded = {
|
14
|
+
detect: function (str) {
|
15
|
+
// the fact that script doesn't contain any space, but has %20 instead
|
16
|
+
// should be sufficient check for now.
|
17
|
+
if (str.indexOf(' ') == -1) {
|
18
|
+
if (str.indexOf('%20') != -1) return true;
|
19
|
+
if (str.replace(/[^%]+/g, '').length > 3) return true;
|
20
|
+
}
|
21
|
+
return false;
|
22
|
+
},
|
23
|
+
|
24
|
+
unpack: function (str) {
|
25
|
+
if (Urlencoded.detect(str)) {
|
26
|
+
return unescape(str.replace(/\+/g, '%20'));
|
27
|
+
}
|
28
|
+
return str;
|
29
|
+
},
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
run_tests: function (sanity_test) {
|
34
|
+
var t = sanity_test || new SanityTest();
|
35
|
+
t.test_function(Urlencoded.detect, "Urlencoded.detect");
|
36
|
+
t.expect('', false);
|
37
|
+
t.expect('var a = b', false);
|
38
|
+
t.expect('var%20a+=+b', true);
|
39
|
+
t.expect('var%20a=b', true);
|
40
|
+
t.expect('var%20%21%22', true);
|
41
|
+
t.test_function(Urlencoded.unpack, 'Urlencoded.unpack');
|
42
|
+
t.expect('', '');
|
43
|
+
t.expect('abcd', 'abcd');
|
44
|
+
t.expect('var a = b', 'var a = b');
|
45
|
+
t.expect('var%20a=b', 'var a=b');
|
46
|
+
t.expect('var%20a+=+b', 'var a = b');
|
47
|
+
return t;
|
48
|
+
}
|
49
|
+
|
50
|
+
|
51
|
+
}
|
data/lib/js-beautify.rb
ADDED
File without changes
|