JE/escape.pl

filter: Statementstmt 100% 74 / 74 Branchbran 100% 30 / 30 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod n/a totaltotal 100% 115 / 115 CC 16 SCAR 12.0
CC
16
Cov
100%
_decodeURI
5.0
_decodeURIComponent
5.0
_encodeURI
3.0
CRAP 3.3
« JE/Scope.pm ↑ Summary JE/String.pm »
1 package JE;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings; no warnings 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use Encode 2.08 qw< decode_utf8 encode_utf8 FB_CROAK >;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 25 ▶sub _decodeURI {
Subroutine _decodeURI: called CC=5 SCAR=16.1
8 25 my $global = shift;
9 25 my $str = shift;
10 25 ▶ $str = defined $str ? $str->to_string->value : 'undefined';
Branch: 1 branch
BranchTrueFalseTotal
defined $str ? : 23 2 25
11 25 ▶ $str =~ /%(?![a-fA-F0-9]{2})(.{0,2})/
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /%(?![a-fA-F0-9]{2})(.{0,2})/ and require JE::Object::Error::URIError, die("JE::Object::Error::URIError"->new($global, add_line_number("Invalid escape %$1 in URI"))) 7 18 25
12 and require JE::Object::Error::URIError,
13 die
14 JE::Object::Error::URIError->new(
15 $global,
16 add_line_number
17 "Invalid escape %$1 in URI"
18 );
19  
20 18 $str = encode_utf8 $str;
21  
22 # [;/?:@&=+$,#] do not get unescaped
23 18 $str =~ s/%(?!2[346bcf]|3[abdf]|40)
24 145 ([0-9a-f]{2})/chr hex $1/iegx;
25
26 18 ▶ if (do{
Branch: 1 branch
BranchTrueFalseTotal
if (do { local $@; eval { do { $str = &decode_utf8($str, 1) } }; $@ }) 4 14 18
27 18 local $@;
28 18 eval {
29 18 $str = decode_utf8 $str, FB_CROAK;
30 };
31 18 $@
32 }) {
33 4 require JE'Object'Error'URIError;
34 4 die JE::Object::Error::URIError
35 ->new(
36 $global,
37 add_line_number
38 'Malformed UTF-8 in URI'
39 );
40 }
41
42 $str =~
43 14 ▶ /^[\0-\x{10ffff}]*\z/
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /^[\0-\x{10ffff}]*\z/ or require JE::Object::Error::URIError, die("JE::Object::Error::URIError"->new($global, add_line_number("Malformed UTF-8 in URI"))) 12 2 14
44 or require JE::Object::Error::URIError,
45 die JE::Object::Error::URIError->new(
46 $global, add_line_number
47 'Malformed UTF-8 in URI');
48  
49 12 JE::String->_new($global, $str);
50 }
51  
52 25 ▶sub _decodeURIComponent {
Subroutine _decodeURIComponent: called CC=5 SCAR=16.1
53 25 my $global = shift;
54 25 my $str = shift;
55 25 ▶ $str = defined $str ? $str->to_string->value : 'undefined';
Branch: 1 branch
BranchTrueFalseTotal
defined $str ? : 23 2 25
56 25 ▶ $str =~ /%(?![a-fA-F0-9]{2})(.{0,2})/
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /%(?![a-fA-F0-9]{2})(.{0,2})/ and require JE::Object::Error::URIError, die("JE::Object::Error::URIError"->new($global, add_line_number("Invalid escape %$1 in URI"))) 7 18 25
57 and require JE::Object::Error::URIError,
58 die
59 JE::Object::Error::URIError->new(
60 $global,
61 add_line_number
62 "Invalid escape %$1 in URI"
63 );
64  
65 18 $str = encode_utf8 $str;
66  
67 # [;/?:@&=+$,#] do not get unescaped
68 18 $str =~ s/%([0-9a-f]{2})/chr hex $1/iegx;
69
70 18 ▶ if (do{
Branch: 1 branch
BranchTrueFalseTotal
if (do { local $@; eval { do { $str = &decode_utf8($str, 1) } }; $@ }) 4 14 18
71 18 local $@;
72 18 eval {
73 18 $str = decode_utf8 $str, FB_CROAK;
74 };
75 18 $@
76 }) {
77 4 require JE'Object'Error'URIError;
78 4 die JE::Object::Error::URIError
79 ->new(
80 $global,
81 add_line_number
82 'Malformed UTF-8 in URI'
83 );
84 }
85
86 $str =~
87 14 ▶ /^[\0-\x{10ffff}]*\z/
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /^[\0-\x{10ffff}]*\z/ or require JE::Object::Error::URIError, die("JE::Object::Error::URIError"->new($global, add_line_number("Malformed UTF-8 in URI"))) 12 2 14
88 or require JE::Object::Error::URIError,
89 die JE::Object::Error::URIError->new(
90 $global, add_line_number
91 'Malformed UTF-8 in URI');
92  
93 12 JE::String->_new($global, $str);
94 }
95  
96 12 ▶sub _encodeURI {
Subroutine _encodeURI: called CC=3 SCAR=11.0
97 12 my $global = shift;
98 12 my $str = shift;
99 12 ▶ $str = defined $str ? $str->to_string->value : 'undefined';
Branch: 1 branch
BranchTrueFalseTotal
defined $str ? : 10 2 12
100 12 ▶ $str =~ /(\p{Cs})/ and
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /(\p{Cs})/ and require JE::Object::Error::URIError, die("JE::Object::Error::URIError"->new($global, add_line_number(sprintf("Unpaired surrogate 0x%x in string", ord $1)))) 3 9 12
101 require JE::Object::Error::URIError,
102 die JE::Object::Error::URIError->new($global,
103 add_line_number sprintf
104 "Unpaired surrogate 0x%x in string", ord $1
105 );
106  
107 9 $str = encode_utf8 $str;
108  
109 9 $str =~
110 s< ([^;/?:@&=+\$,A-Za-z0-9\-_.!~*'()#]) >
111 58 < sprintf '%%%02X', ord $1 >egx;
112
113 9 JE::String->_new($global, $str);
114 }
115  
116 12 ▶sub _encodeURIComponent {
Subroutine _encodeURIComponent: called CC=3 SCAR=11.0
117 12 my $global = shift;
118 12 my $str = shift;
119 12 ▶ $str = defined $str ? $str->to_string->value : 'undefined';
Branch: 1 branch
BranchTrueFalseTotal
defined $str ? : 10 2 12
120 12 ▶ $str =~ /(\p{Cs})/ and
Branch: 1 branch
BranchTrueFalseTotal
$str =~ /(\p{Cs})/ and require JE::Object::Error::URIError, die("JE::Object::Error::URIError"->new($global, add_line_number(sprintf("Unpaired surrogate 0x%x in string", ord $1)))) 3 9 12
121 require JE::Object::Error::URIError,
122 die JE::Object::Error::URIError->new(
123 $global, add_line_number sprintf
124 "Unpaired surrogate 0x%x in string", ord $1
125 );
126  
127 9 $str = encode_utf8 $str;
128  
129 9 $str =~ s< ([^A-Za-z0-9\-_.!~*'()]) >
130 69 < sprintf '%%%02X', ord $1 >egx;
131
132 9 JE::String->_new($global, $str);
133 }
134  
135 8 ▶sub _escape {
Subroutine _escape: called CC=3 SCAR=11.0
136 8 my $global = shift;
137 8 ▶ my $str = defined $_[0] ? shift->to_string->value16 : 'undefined';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 6 2 8
138 3 ▶ no warnings 'utf8';
Subroutine BEGIN: called CC=1 SCAR=0.0
139 8 $str =~ s< ([^A-Za-z0-9\@*_+\-./]) >
140 193 ▶ [ sprintf '%%' . (
Branch: 1 branch
BranchTrueFalseTotal
ord $1 <= 255 ? : 190 3 193
141 ord $1 <= 0xff
142 ? '%02'
143 : 'u%04'
144 ) . 'x', ord $1 ]egx;
145 8 JE::String->_new($global, $str);
146 }
147  
148 9 ▶sub _unescape {
Subroutine _unescape: called CC=2 SCAR=6.9
149 9 my $global = shift;
150 9 ▶ my $str = defined $_[0] ? shift->to_string->value16 : 'undefined';
Branch: 1 branch
BranchTrueFalseTotal
defined $_[0] ? : 7 2 9
151 9 $str =~s<%(?:u([a-f0-9]{4})|([a-f0-9]{2}))>
152 7 < chr hex $+ >egix;
153 9 JE::String->_new($global, $str);
154 }
155  
156 3 1
« JE/Scope.pm ↑ Summary JE/String.pm »