Permalink
Browse files

fix small problems like make split_query 'our' and fix context issue …

…with uri_unescape
  • Loading branch information...
ronaldxs committed Aug 14, 2011
1 parent c7e52d3 commit 703048f958313a64a510abd770506e3c48573ef1
Showing with 25 additions and 25 deletions.
  1. +1 −2 lib/URI.pm
  2. +23 −23 lib/URI/Escape.pm
  3. +1 −0 t/escape.t
View
@@ -79,12 +79,11 @@ method parse (Str $str) {
}
}
-sub split_query(Str $query) {
+our sub split_query(Str $query) {
my %query_form;
for map { [split(/<[=]>/, $_) ]}, split(/<[&;]>/, $query) -> $qmap {
for (0, 1) -> $i { # could go past 1 in theory ...
- $qmap[ $i ] ~~ s:g/\+/ /;
$qmap[ $i ] = uri_unescape($qmap[ $i ]);
}
if %query_form.exists($qmap[0]) {
View
@@ -68,33 +68,33 @@ package URI::Escape {
$last_pos = $/.to;
}
$rc ~= $s.substr($last_pos);
- $rc ~~ s:g/\+/ /;
+ $rc .= trans('+' => ' ');
@rc.push($rc);
}
- return @rc;
+ return do given @rc.elems { # this might be simplified some day
+ when 0 { Nil }
+ when 1 { @rc[0] }
+ default { @rc }
+ }
}
- sub uri_unescape_utf8 () {
- }
-
-}
-
-# Stole parts from Masak November::CGI and parts from Parrot's UTF-8 decode
-sub utf8_octets_2_codepoint(@octets) {
- if @octets[ 0 ] < 0x80 { # completeness
- return @octets[0], 1
- }
-
- my $len = 2;
-
- while 0x80 +> $len +& @octets[0] and ++$len <= 6 {}
-
- my $max_shift = 6 * ($len -1);
- my $code_point = reduce {
- $^a + @octets[ $^b ] +& 0x3F +< ($max_shift - 6 * $^b)
- }, 0x7F +> $len +& @octets[0] +< $max_shift, 1 ..^ $len;
-
- return $code_point, $len;
+ # Stole parts from Masak November::CGI and parts from Parrot's UTF-8 decode
+ sub utf8_octets_2_codepoint(@octets) {
+ if @octets[ 0 ] < 0x80 { # completeness
+ return @octets[0], 1
+ }
+
+ my $len = 2;
+
+ while 0x80 +> $len +& @octets[0] and ++$len <= 6 {}
+
+ my $max_shift = 6 * ($len -1);
+ my $code_point = reduce {
+ $^a + @octets[ $^b ] +& 0x3F +< ($max_shift - 6 * $^b)
+ }, 0x7F +> $len +& @octets[0] +< $max_shift, 1 ..^ $len;
+
+ return $code_point, $len;
+ }
}
=begin pod
View
@@ -19,6 +19,7 @@ ok not defined uri_escape(Str), 'undef returns undef';
is uri_unescape(no_utf8 => True, '%7C%25abc%E5'), '|%abcå', 'basic latin-1 unescape test';
is uri_unescape('%7C%25abc%C3%A5'), '|%abcå', 'basic utf8 unescape test';
+my $x = uri_unescape('%7C%25abc%C3%A5');
is uri_unescape("%40A%42", "CDE", "F%47++H"), ['@AB', 'CDE', 'FG H'],
'unescape list';

0 comments on commit 703048f

Please sign in to comment.