File: fix-random-var-name-issue

package info (click to toggle)
libjavascript-packer-perl 1.006003-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 380 kB
  • ctags: 175
  • sloc: perl: 2,717; makefile: 2
file content (112 lines) | stat: -rw-r--r-- 9,857 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
Description: Fix random var name issue
 Test failures were due to randomisation of keys %foo.
 .
 A sort was added to all calls to keys. The tests were
 modified to suit the now ordered keys results.
Bug: https://github.com/nevesenin/javascript-packer-perl/issues/8
Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=711629
Author: dod
--- a/lib/JavaScript/Packer.pm
+++ b/lib/JavaScript/Packer.pm
@@ -413,7 +413,7 @@
         my %shrunk_vars = map { $_ => 1 } ( ${$javascript} =~ /$SHRINK_VARS->{SHRUNK}/g );
 
         my $cnt = 0;
-        foreach my $shrunk_var ( keys( %shrunk_vars ) ) {
+        foreach my $shrunk_var ( sort keys( %shrunk_vars ) ) {
             my $short_id;
             do {
                 $short_id = $self->_encode52( $cnt++ );
@@ -438,7 +438,7 @@
             $words->{$_}->{count}++;
         }
 
-        WORD: foreach my $word ( sort { $words->{$b}->{count} <=> $words->{$a}->{count} } keys( %{$words} ) ) {
+        WORD: foreach my $word ( sort { $words->{$b}->{count} <=> $words->{$a}->{count} } sort keys( %{$words} ) ) {
 
             if ( exists( $words->{$word}->{encoded} ) and $words->{$word}->{encoded} eq $word ) {
                 next WORD;
@@ -473,7 +473,7 @@
 
         my ( @pk, @pattern ) = ( (), () );
 
-        foreach ( sort { $words->{$a}->{index} <=> $words->{$b}->{index} } keys( %{$words} ) ) {
+        foreach ( sort { $words->{$a}->{index} <=> $words->{$b}->{index} } sort keys( %{$words} ) ) {
             $packed_length -= ( $words->{$_}->{count} * $words->{$_}->{minus} );
 
             if ( $words->{$_}->{encoded} ne $_ ) {
@@ -645,7 +645,7 @@
         if ( $do_shrink ) {
 
             my $cnt = 0;
-            foreach my $block_var ( keys( %block_vars ) ) {
+            foreach my $block_var ( sort keys( %block_vars ) ) {
                 if ( length( $block_var ) ) {
                     while ( $block =~ /$SHRINK_VARS->{PREFIX}\Q$cnt\E\b/ ) {
                         $cnt++;
--- a/t/scripts/s2-expected.js
+++ b/t/scripts/s2-expected.js
@@ -1,2 +1,2 @@
-function(b){var a='blah blubb';var d=3;alert(a);var f=1;//@a
-var e=b;/*@abcd var f=1;@*/abcd var c=$H()};/*@abcd var x=1;@*/
\ No newline at end of file
+function(c){var a='blah blubb';var e=3;alert(a);var d=1;//@a
+var b=c;/*@abcd var d=1;@*/abcd var f=$H()};/*@abcd var x=1;@*/
\ No newline at end of file
--- a/t/scripts/s3-expected.js
+++ b/t/scripts/s3-expected.js
@@ -1 +1 @@
-eval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[024-9]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('2(b){0 a=\'7 9\';0 d=3;8(a);0 6=1;//@a\n0 e=b;/*@4 0 6=1;@*/4 0 c=$5()};',[],10,'var||function||abcd|H|f|blah|alert|blubb'.split('|'),0,{}))
\ No newline at end of file
+eval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[024-9]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5(c){0 a=\'2 9\';0 e=3;8(a);0 d=1;//@a\n0 b=c;/*@4 0 d=1;@*/4 0 6=$7()};',[],10,'var||blah||abcd|function|f|H|alert|blubb'.split('|'),0,{}))
\ No newline at end of file
--- a/t/scripts/s4-expected.js
+++ b/t/scripts/s4-expected.js
@@ -1,2 +1,2 @@
-function(b){var a='blah blubb';var d=3;alert(a);var f=1;//@a
-var e=b;/*@abcd var f=1;@*/abcd var c=$H()};/*@abcd var x=1;@*/
\ No newline at end of file
+function(c){var a='blah blubb';var e=3;alert(a);var d=1;//@a
+var b=c;/*@abcd var d=1;@*/abcd var f=$H()};/*@abcd var x=1;@*/
\ No newline at end of file
--- a/t/scripts/s5-expected.js
+++ b/t/scripts/s5-expected.js
@@ -1 +1 @@
-eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([2-9h-zB-Z]|1[0-9a-zA-Z])'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5 I=7 3(){5 c=7 Y();5 d=3(g){8(!g.2(\'F\'))n;7 B.u(\'/9\'+g.2(\'F\')+\'x.w?\'+6.h(6.l()*m)+\'=\'+6.h(6.l()*m),{v:\'2\',y:3(a){5 f=7 K(\'R\').o(a.t.1k());f.1j(\'1c\').s(3(b){5 e=7 1b();e.N=b.10(\'N\');c[c.J]=e})}});8(g.2(\'L\')){g.2(\'L\').s(3(e){d(e)})}}n{Q:3(){5 b=C.U();b.s(3(e){d(e)})}}}5 9=7 3(){n{r:3(){5 g=$A(9.r.14);5 a=g.1d();8(!a){n}5 f=7 K(\'R\');f.13({\'19\':\'M\',\'1o\':\'M\'});8( $(\'i\').18()){7 q.1a(\'i\',{11:3(){7 B.u(\'/9\'+a+\'x.w?\'+6.h(6.l()*m)+\'=\'+6.h(6.l()*m),{v:\'2\',y:3(e){5 b=f.o(e.t); $(\'i\').o(b);7 q.G(\'i\',{H:0.E})}})},15:0.E})}O{7 B.u(\'/9\'+a+\'x.w?\'+6.h(6.l()*m)+\'=\'+6.h(6.l()*m),{v:\'2\',y:3(e){ $(\'i\').o(f.o(e.t));7 q.G(\'i\',{H:0.12})}})}}}}5 j=0;T.4.17({D:3(e){n 1i.D(e)},X:3(e){n e.16()}});3 p(b,e){b=b?b:\'/\';8(!j&&b){j=1;9.r(b);C.r(b);z()}}3 1h(b,e){8(!j){4.S(b,e)}p(b,e)}3 z(){5 e=$A(q.1f);8(e.J>0){Z("z();",1n)}O{j=0}}T.1m=3(){4.1e();4.1l(p);C.V();k=4.1g();k=k?k:\'/\';8(4.W()){8(!j){4.S(k,P)}p(k,P)}I.Q()}',[],87,'||get|function|dhtmlHistory|var|Math|new|if|content||||||||round|div_content|wait|initialLocation|random|99999|return|update|handle_location|Effect|process|each|responseText|Request|method|htm|index|onComplete|reset_wait||Ajax|menu|toJSON|01|loc|Appear|from|image|length|Element|subs|0px|src|else|null|preload|div|add|window|get_menu_hash|init|isFirstLoad|fromJSON|Array|setTimeout|readAttribute|afterFinish|00|setStyle|arguments|to|evalJSON|create|visible|padding|Fade|Image|img|shift|initialize|Queue|getCurrentLocation|handle_click|Object|select|stripScripts|addListener|onload|1000|margin'.split('|'),0,{}))
\ No newline at end of file
+eval(function(p,a,c,k,e,r){e=function(c){return(c<62?'':e(parseInt(c/62)))+((c=c%62)>35?String.fromCharCode(c+29):c.toString(36))};if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'([2-9h-zB-Z]|1[0-9a-zA-Z])'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('5 L=7 3(){5 g=7 W();5 f=3(e){9(!e.4(\'N\'))l;7 s.t(\'/h\'+e.4(\'N\')+\'w.v?\'+6.m(6.k()*8)+\'=\'+6.m(6.k()*8),{y:\'4\',z:3(d){5 c=7 G(\'I\').o(d.C.1m());c.1i(\'1a\').u(3(b){5 a=7 Y();a.Q=b.1h(\'Q\');g[g.M]=a})}});9(e.4(\'R\')){e.4(\'R\').u(3(a){f(a)})}}l{P:3(){5 b=x.18();b.u(3(a){f(a)})}}}5 h=7 3(){l{r:3(){5 c=$A(h.r.13);5 e=c.1l();9(!e){l}5 d=7 G(\'I\');d.1j({\'1g\':\'E\',\'1e\':\'E\'});9( $(\'i\').1o()){7 p.X(\'i\',{12:3(){7 s.t(\'/h\'+e+\'w.v?\'+6.m(6.k()*8)+\'=\'+6.m(6.k()*8),{y:\'4\',z:3(a){5 b=d.o(a.C); $(\'i\').o(b);7 p.F(\'i\',{K:0.D})}})},1n:0.D})}J{7 s.t(\'/h\'+e+\'w.v?\'+6.m(6.k()*8)+\'=\'+6.m(6.k()*8),{y:\'4\',z:3(a){ $(\'i\').o(d.o(a.C));7 p.F(\'i\',{K:0.U})}})}}}}5 n=0;T.2.14({S:3(a){l Z.S(a)},16:3(a){l a.15()}});3 q(b,a){b=b?b:\'/\';9(!n&&b){n=1;h.r(b);x.r(b);B()}}3 19(b,a){9(!n){2.H(b,a)}q(b,a)}3 B(){5 a=$A(p.10);9(a.M>0){1k("B();",V)}J{n=0}}T.1f=3(){2.1c();2.11(q);x.1b();j=2.17();j=j?j:\'/\';9(2.1d()){9(!n){2.H(j,O)}q(j,O)}L.P()}',[],87,'||dhtmlHistory|function|get|var|Math|new|99999|if||||||||content|div_content|initialLocation|random|return|round|wait|update|Effect|handle_location|process|Ajax|Request|each|htm|index|menu|method|onComplete||reset_wait|responseText|01|0px|Appear|Element|add|div|else|from|image|length|loc|null|preload|src|subs|toJSON|window|00|1000|Array|Fade|Image|Object|Queue|addListener|afterFinish|arguments|create|evalJSON|fromJSON|getCurrentLocation|get_menu_hash|handle_click|img|init|initialize|isFirstLoad|margin|onload|padding|readAttribute|select|setStyle|setTimeout|shift|stripScripts|to|visible'.split('|'),0,{}))
\ No newline at end of file
--- a/t/scripts/s10-expected.js
+++ b/t/scripts/s10-expected.js
@@ -1 +1 @@
-function initScript(){var a=parseXML("config.xml").getElementsByTagName("config");var b=parseXML('konfig.xml').getElementsByTagName('konfig');var c='conf.xml';var e='conf';var d=parseXML(c).getElementsByTagName(e)}
\ No newline at end of file
+function initScript(){var c=parseXML("config.xml").getElementsByTagName("config");var e=parseXML('konfig.xml').getElementsByTagName('konfig');var b='conf.xml';var a='conf';var d=parseXML(b).getElementsByTagName(a)}
\ No newline at end of file
--- a/t/scripts/s8-expected.js
+++ b/t/scripts/s8-expected.js
@@ -1 +1 @@
-function(b){var d=x;var c=y;var a=(function(){return[].concat(arguments)[0][0]!==1})(1,do_somthing(do_something_else(d,c),d));if(a)arrayProto.concat=concat}
\ No newline at end of file
+function(d){var b=x;var c=y;var a=(function(){return[].concat(arguments)[0][0]!==1})(1,do_somthing(do_something_else(b,c),b));if(a)arrayProto.concat=concat}
\ No newline at end of file
--- a/t/02-io.t
+++ b/t/02-io.t
@@ -25,7 +25,7 @@
     fileTest( 's7',  'clean',     'compression level "clean" function as argument' );
     fileTest( 's8',  'shrink',    'compression level "shrink" function as argument' );
     fileTest( 's9',  'shrink',    'compression level "shrink" with _no_shrink_ argument' );
-    fileTest( 's10', 'shrink',    'compression level "shrink" with qouted args' );
+    fileTest( 's10', 'shrink',    'compression level "shrink" with quoted args' );
 
     my $packer = JavaScript::Packer->init();
 
@@ -52,7 +52,7 @@
     is(
         $var,
         '/* BSD */'
-            . "\neval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[01]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('0 1=2;',[],2,'var|x'.split('|'),0,{}))",
+            . "\neval(function(p,a,c,k,e,r){e=String;if('0'.replace(0,e)==0){while(c--)r[e(c)]=k[c];k=[function(e){return r[e]||e}];e=function(){return'[01]'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\\\b'+e(c)+'\\\\b','g'),k[c]);return p}('1 0=2;',[],2,'x|var'.split('|'),0,{}))",
         'copyright option compression level "obfuscate"'
     );