line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Win32::ShellQuote; |
2
|
2
|
|
|
2
|
|
13901
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
64
|
|
3
|
2
|
|
|
2
|
|
8
|
use warnings FATAL => 'all'; |
|
2
|
|
|
|
|
1
|
|
|
2
|
|
|
|
|
67
|
|
4
|
2
|
|
|
2
|
|
14
|
use base 'Exporter'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
140
|
|
5
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
963
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '0.002003'; |
8
|
|
|
|
|
|
|
$VERSION = eval $VERSION; |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
11
|
|
|
|
|
|
|
quote_native |
12
|
|
|
|
|
|
|
quote_cmd |
13
|
|
|
|
|
|
|
quote_system_list |
14
|
|
|
|
|
|
|
quote_system_string |
15
|
|
|
|
|
|
|
quote_system |
16
|
|
|
|
|
|
|
quote_system_cmd |
17
|
|
|
|
|
|
|
quote_literal |
18
|
|
|
|
|
|
|
cmd_escape |
19
|
|
|
|
|
|
|
); |
20
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => [@EXPORT_OK]); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub quote_native { |
23
|
0
|
|
|
0
|
1
|
|
return join q{ }, quote_system_list(@_); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub quote_cmd { |
27
|
0
|
|
|
0
|
1
|
|
return cmd_escape(quote_native(@_)); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub quote_system_list { |
31
|
|
|
|
|
|
|
# have to force quoting, or perl might try to use cmd anyway |
32
|
0
|
|
|
0
|
1
|
|
return map { quote_literal($_, 1) } @_; |
|
0
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub quote_system_string { |
36
|
0
|
|
|
0
|
1
|
|
my $args = quote_native(@_); |
37
|
|
|
|
|
|
|
|
38
|
0
|
0
|
|
|
|
|
if (_has_shell_metachars($args)) { |
39
|
0
|
|
|
|
|
|
$args = cmd_escape($args); |
40
|
|
|
|
|
|
|
} |
41
|
0
|
|
|
|
|
|
return $args; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub quote_system { |
45
|
0
|
0
|
|
0
|
1
|
|
if (@_ > 1) { |
46
|
0
|
|
|
|
|
|
return quote_system_list(@_); |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
else { |
49
|
0
|
|
|
|
|
|
return quote_system_string(@_); |
50
|
|
|
|
|
|
|
} |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub quote_system_cmd { |
54
|
|
|
|
|
|
|
# force cmd, even when running through system |
55
|
0
|
|
|
0
|
1
|
|
my $args = quote_native(@_); |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
|
if (! _has_shell_metachars($args)) { |
58
|
|
|
|
|
|
|
# IT BURNS LOOK AWAY |
59
|
0
|
|
|
|
|
|
return '%PATH:~0,0%' . cmd_escape($args); |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
|
return cmd_escape($args); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub cmd_escape { |
66
|
0
|
|
|
0
|
1
|
|
my $string = shift; |
67
|
0
|
0
|
|
|
|
|
if ($string =~ /[\r\n\0]/) { |
68
|
0
|
|
|
|
|
|
croak "can't quote newlines to pass through cmd.exe"; |
69
|
|
|
|
|
|
|
} |
70
|
0
|
|
|
|
|
|
$string =~ s/([()%!^"<>&|])/^$1/g; |
71
|
0
|
|
|
|
|
|
return $string; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub quote_literal { |
75
|
0
|
|
|
0
|
1
|
|
my ($text, $force) = @_; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# basic argument quoting. uses backslashes and quotes to escape |
78
|
|
|
|
|
|
|
# everything. |
79
|
0
|
0
|
0
|
|
|
|
if (!$force && $text ne '' && $text !~ /[ \t\n\x0b"]/) { |
|
|
|
0
|
|
|
|
|
80
|
|
|
|
|
|
|
# no quoting needed |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
else { |
83
|
0
|
|
|
|
|
|
$text =~ s{(\\*)(?="|\z)}{$1$1}g; |
84
|
0
|
|
|
|
|
|
$text =~ s{"}{\\"}g; |
85
|
0
|
|
|
|
|
|
$text = qq{"$text"}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
return $text; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# derived from rules in code in win32.c |
92
|
|
|
|
|
|
|
sub _has_shell_metachars { |
93
|
0
|
|
|
0
|
|
|
my $string = shift; |
94
|
|
|
|
|
|
|
|
95
|
0
|
0
|
|
|
|
|
return 1 |
96
|
|
|
|
|
|
|
if $string =~ /%/; |
97
|
0
|
|
|
|
|
|
$string =~ s/(['"]).*?(\1|\z)//; |
98
|
0
|
|
|
|
|
|
return $string =~ /[<>|]/; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
1; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
__END__ |