Permalink
Browse files

simply URL escaping; t/escape.t now passes

  • Loading branch information...
1 parent dd1312b commit 3962d71976f2deb8cb93135d2f513dca855bf054 @moritz moritz committed Mar 29, 2012
Showing with 6 additions and 13 deletions.
  1. +6 −13 lib/URI/Escape.pm
View
@@ -16,13 +16,11 @@ package URI::Escape {
# commented line below used to work ...
# token artifact_unreserved {<[!*'()] +IETF::RFC_Grammar::URI::unreserved>};
- sub uri_escape($s is copy, Bool :$no_utf8 = False) is export {
- my $rc;
- my $last_pos = 0;
-
- while my $escape = $s ~~ m:c/<- [!*'()\-._~A..Za..z0..9]>+/ {
- $rc ~= $s.substr($last_pos, $/.from - $last_pos);
- $rc ~= ($escape.comb().map: {
+ sub uri_escape($s, Bool :$no_utf8 = False) is export {
+ return $s unless defined $s;
+ $s.subst(:g, rx/<- [!*'()\-._~A..Za..z0..9]>+/,
+ -> $escape {
+ ($escape.Str.comb.map: {
( $no_utf8 || ! 0x80 +& ord($_) ) ?? %escapes{ $_ } !!
do {
my $buf = $_.encode;
@@ -31,12 +29,7 @@ package URI::Escape {
}
}
}).join;
- $last_pos = $/.to;
- }
- # $s.defined test needed because of bug fixed in nom
- if $s.defined and $s.chars > $last_pos { $rc ~= $s.substr($last_pos) }
-
- return $rc;
+ });
}
# todo - automatic invalid UTF-8 detection

0 comments on commit 3962d71

Please sign in to comment.