| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package JE; | 
| 2 |  |  |  |  |  |  |  | 
| 3 | 3 |  |  | 3 |  | 1365 | use strict; | 
|  | 3 |  |  |  |  | 6 |  | 
|  | 3 |  |  |  |  | 112 |  | 
| 4 | 3 |  |  | 3 |  | 14 | use warnings; no warnings 'utf8'; | 
|  | 3 |  |  | 3 |  | 4 |  | 
|  | 3 |  |  |  |  | 84 |  | 
|  | 3 |  |  |  |  | 9 |  | 
|  | 3 |  |  |  |  | 4 |  | 
|  | 3 |  |  |  |  | 115 |  | 
| 5 | 3 |  |  | 3 |  | 14 | use Encode 2.08 qw< decode_utf8 encode_utf8 FB_CROAK >; | 
|  | 3 |  |  |  |  | 7600 |  | 
|  | 3 |  |  |  |  | 2200 |  | 
| 6 |  |  |  |  |  |  |  | 
| 7 |  |  |  |  |  |  | sub _decodeURI { | 
| 8 | 25 |  |  | 25 |  | 24 | my $global = shift; | 
| 9 | 25 |  |  |  |  | 19 | my $str = shift; | 
| 10 | 25 | 100 |  |  |  | 77 | $str = defined $str ? $str->to_string->value : 'undefined'; | 
| 11 | 25 | 100 |  |  |  | 211 | $str =~ /%(?![a-fA-F0-9]{2})(.{0,2})/ | 
| 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 |  |  |  |  | 55 | $str = encode_utf8 $str; | 
| 21 |  |  |  |  |  |  |  | 
| 22 |  |  |  |  |  |  | # [;/?:@&=+$,#] do not get unescaped | 
| 23 | 18 |  |  |  |  | 136 | $str =~ s/%(?!2[346bcf]|3[abdf]|40) | 
| 24 | 145 |  |  |  |  | 262 | ([0-9a-f]{2})/chr hex $1/iegx; | 
| 25 |  |  |  |  |  |  |  | 
| 26 | 18 | 100 |  |  |  | 16 | if (do{ | 
| 27 | 18 |  |  |  |  | 19 | local $@; | 
| 28 | 18 |  |  |  |  | 21 | eval { | 
| 29 | 18 |  |  |  |  | 57 | $str = decode_utf8 $str, FB_CROAK; | 
| 30 |  |  |  |  |  |  | }; | 
| 31 | 18 |  |  |  |  | 380 | $@ | 
| 32 |  |  |  |  |  |  | }) { | 
| 33 | 4 |  |  |  |  | 21 | require JE'Object'Error'URIError; | 
| 34 | 4 |  |  |  |  | 11 | 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 | 100 |  |  |  | 89 | /^[\0-\x{10ffff}]*\z/ | 
| 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 |  |  |  |  | 34 | JE::String->_new($global, $str); | 
| 50 |  |  |  |  |  |  | } | 
| 51 |  |  |  |  |  |  |  | 
| 52 |  |  |  |  |  |  | sub _decodeURIComponent { | 
| 53 | 25 |  |  | 25 |  | 31 | my $global = shift; | 
| 54 | 25 |  |  |  |  | 21 | my $str = shift; | 
| 55 | 25 | 100 |  |  |  | 85 | $str = defined $str ? $str->to_string->value : 'undefined'; | 
| 56 | 25 | 100 |  |  |  | 222 | $str =~ /%(?![a-fA-F0-9]{2})(.{0,2})/ | 
| 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 |  |  |  |  | 49 | $str = encode_utf8 $str; | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  | # [;/?:@&=+$,#] do not get unescaped | 
| 68 | 18 |  |  |  |  | 132 | $str =~ s/%([0-9a-f]{2})/chr hex $1/iegx; | 
|  | 156 |  |  |  |  | 264 |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 | 18 | 100 |  |  |  | 21 | if (do{ | 
| 71 | 18 |  |  |  |  | 16 | local $@; | 
| 72 | 18 |  |  |  |  | 21 | eval { | 
| 73 | 18 |  |  |  |  | 60 | $str = decode_utf8 $str, FB_CROAK; | 
| 74 |  |  |  |  |  |  | }; | 
| 75 | 18 |  |  |  |  | 372 | $@ | 
| 76 |  |  |  |  |  |  | }) { | 
| 77 | 4 |  |  |  |  | 23 | require JE'Object'Error'URIError; | 
| 78 | 4 |  |  |  |  | 13 | 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 | 100 |  |  |  | 87 | /^[\0-\x{10ffff}]*\z/ | 
| 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 |  |  |  |  | 40 | JE::String->_new($global, $str); | 
| 94 |  |  |  |  |  |  | } | 
| 95 |  |  |  |  |  |  |  | 
| 96 |  |  |  |  |  |  | sub _encodeURI { | 
| 97 | 12 |  |  | 12 |  | 15 | my $global = shift; | 
| 98 | 12 |  |  |  |  | 12 | my $str = shift; | 
| 99 | 12 | 100 |  |  |  | 40 | $str = defined $str ? $str->to_string->value : 'undefined'; | 
| 100 | 12 | 100 |  |  |  | 92 | $str =~ /(\p{Cs})/ and | 
| 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 |  |  |  |  | 23 | $str = encode_utf8 $str; | 
| 108 |  |  |  |  |  |  |  | 
| 109 | 9 |  |  |  |  | 59 | $str =~ | 
| 110 |  |  |  |  |  |  | s< ([^;/?:@&=+\$,A-Za-z0-9\-_.!~*'()#]) > | 
| 111 | 58 |  |  |  |  | 106 | < sprintf '%%%02X', ord $1           >egx; | 
| 112 |  |  |  |  |  |  |  | 
| 113 | 9 |  |  |  |  | 24 | JE::String->_new($global, $str); | 
| 114 |  |  |  |  |  |  | } | 
| 115 |  |  |  |  |  |  |  | 
| 116 |  |  |  |  |  |  | sub _encodeURIComponent { | 
| 117 | 12 |  |  | 12 |  | 13 | my $global = shift; | 
| 118 | 12 |  |  |  |  | 14 | my $str = shift; | 
| 119 | 12 | 100 |  |  |  | 47 | $str = defined $str ? $str->to_string->value : 'undefined'; | 
| 120 | 12 | 100 |  |  |  | 94 | $str =~ /(\p{Cs})/ and | 
| 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 |  |  |  |  | 24 | $str = encode_utf8 $str; | 
| 128 |  |  |  |  |  |  |  | 
| 129 | 9 |  |  |  |  | 57 | $str =~ s< ([^A-Za-z0-9\-_.!~*'()])  > | 
| 130 | 69 |  |  |  |  | 130 | < sprintf '%%%02X', ord $1 >egx; | 
| 131 |  |  |  |  |  |  |  | 
| 132 | 9 |  |  |  |  | 24 | JE::String->_new($global, $str); | 
| 133 |  |  |  |  |  |  | } | 
| 134 |  |  |  |  |  |  |  | 
| 135 |  |  |  |  |  |  | sub _escape { | 
| 136 | 8 |  |  | 8 |  | 10 | my $global = shift; | 
| 137 | 8 | 100 |  |  |  | 35 | my $str = defined $_[0] ? shift->to_string->value16 : 'undefined'; | 
| 138 | 3 |  |  | 3 |  | 1432 | no warnings 'utf8'; | 
|  | 3 |  |  |  |  | 5 |  | 
|  | 3 |  |  |  |  | 528 |  | 
| 139 | 8 |  |  |  |  | 32 | $str =~ s< ([^A-Za-z0-9\@*_+\-./])  > | 
| 140 | 193 | 100 |  |  |  | 606 | [ sprintf '%%' . ( | 
| 141 |  |  |  |  |  |  | ord $1 <= 0xff | 
| 142 |  |  |  |  |  |  | ? '%02' | 
| 143 |  |  |  |  |  |  | : 'u%04' | 
| 144 |  |  |  |  |  |  | ) . 'x', ord $1          ]egx; | 
| 145 | 8 |  |  |  |  | 28 | JE::String->_new($global, $str); | 
| 146 |  |  |  |  |  |  | } | 
| 147 |  |  |  |  |  |  |  | 
| 148 |  |  |  |  |  |  | sub _unescape { | 
| 149 | 9 |  |  | 9 |  | 10 | my $global = shift; | 
| 150 | 9 | 100 |  |  |  | 33 | my $str = defined $_[0] ? shift->to_string->value16 : 'undefined'; | 
| 151 | 9 |  |  |  |  | 29 | $str =~s<%(?:u([a-f0-9]{4})|([a-f0-9]{2}))> | 
| 152 | 7 |  |  |  |  | 23 | < chr hex $+ >egix; | 
| 153 | 9 |  |  |  |  | 27 | JE::String->_new($global, $str); | 
| 154 |  |  |  |  |  |  | } | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | 1 |