line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Value::Escape; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
66287
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
86
|
|
4
|
2
|
|
|
2
|
|
10
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
53
|
|
5
|
2
|
|
|
2
|
|
31
|
use 5.8.1; |
|
2
|
|
|
|
|
10
|
|
|
2
|
|
|
|
|
137
|
|
6
|
2
|
|
|
2
|
|
13
|
use base qw/Exporter/; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
950
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
9
|
|
|
|
|
|
|
our @EXPORT = qw/javascript_value_escape/; |
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw/js/; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my %e = ( |
13
|
|
|
|
|
|
|
q!\\! => 'u005c', |
14
|
|
|
|
|
|
|
q!"! => 'u0022', |
15
|
|
|
|
|
|
|
q!'! => 'u0027', |
16
|
|
|
|
|
|
|
q! 'u003c', |
17
|
|
|
|
|
|
|
q!>! => 'u003e', |
18
|
|
|
|
|
|
|
q!&! => 'u0026', |
19
|
|
|
|
|
|
|
q!=! => 'u003d', |
20
|
|
|
|
|
|
|
q!-! => 'u002d', |
21
|
|
|
|
|
|
|
q!;! => 'u003b', |
22
|
|
|
|
|
|
|
q!+! => 'u002b', |
23
|
|
|
|
|
|
|
"\x{2028}" => 'u2028', |
24
|
|
|
|
|
|
|
"\x{2029}" => 'u2029', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
map { $e{pack('U',$_)} = sprintf("u%04d",$_) } (0x00..0x1f,0x7f); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
*js = \&javascript_value_escape; # alias |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub javascript_value_escape { |
31
|
2
|
|
|
2
|
1
|
1061
|
my $text = shift; |
32
|
2
|
50
|
|
|
|
66
|
$text =~ s!([\\"'<>&=\-;\+\x00-\x1f\x7f]|\x{2028}|\x{2029})!\\$e{$1}!g if defined $text; |
33
|
2
|
|
|
|
|
14
|
return $text; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
__END__ |