Skip to content

Instantly share code, notes, and snippets.

@zigorou
Created February 14, 2010 14:51
Show Gist options
  • Save zigorou/304078 to your computer and use it in GitHub Desktop.
Save zigorou/304078 to your computer and use it in GitHub Desktop.
diff --git a/lib/URI/Template/Restrict.pm b/lib/URI/Template/Restrict.pm
index 22182de..7b93851 100644
--- a/lib/URI/Template/Restrict.pm
+++ b/lib/URI/Template/Restrict.pm
@@ -9,9 +9,11 @@ use List::MoreUtils qw(uniq);
use Unicode::Normalize qw(NFKC);
use URI;
use URI::Escape qw(uri_escape_utf8);
+use URI::Split qw(uri_split uri_join);
use URI::Template::Restrict::Expansion;
-our $VERSION = '0.03';
+our $VERSION = '0.04';
+our $RE_PATH_NORMALIZE = qr{([^a-zA-Z-._~/])};
__PACKAGE__->mk_ro_accessors(qw'template segments');
@@ -78,6 +80,10 @@ sub process_to_string {
sub extract {
my ($self, $uri) = @_;
+ my @uri_splited = uri_split $uri;
+ $uri_splited[2] =~ s|$RE_PATH_NORMALIZE|uri_escape_utf8($1)|gxe;
+ $uri = uri_join @uri_splited;
+
my $re = join '', map { ref $_ ? '('.$_->pattern.')' : quotemeta $_ } @{ $self->segments };
my @match = $uri =~ /$re/;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment