line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package JavaScript::Value::Escape; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
67617
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
111
|
|
4
|
2
|
|
|
2
|
|
12
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
73
|
|
5
|
2
|
|
|
2
|
|
27
|
use 5.8.1; |
|
2
|
|
|
|
|
8
|
|
|
2
|
|
|
|
|
100
|
|
6
|
2
|
|
|
2
|
|
7
|
use base qw/Exporter/; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
776
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
our $VERSION = '0.07'; |
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%04x",$_) } (0x00..0x1f,0x7f); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
*js = \&javascript_value_escape; # alias |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub javascript_value_escape { |
31
|
2
|
|
|
2
|
1
|
431
|
my $text = shift; |
32
|
2
|
50
|
|
|
|
47
|
$text =~ s!([\\"'<>&=\-;\+\x00-\x1f\x7f]|\x{2028}|\x{2029})!\\$e{$1}!g if defined $text; |
33
|
2
|
|
|
|
|
9
|
return $text; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
1; |
37
|
|
|
|
|
|
|
__END__ |