From 15599b7965e9cc33357f164b665bff0b84af9840 Mon Sep 17 00:00:00 2001 From: Artur Khabibullin Date: Wed, 10 Jun 2015 17:32:40 +0300 Subject: [PATCH] #14 match a path in respect of serialier extensions --- lib/Raisin/Routes/Endpoint.pm | 5 +++-- lib/Raisin/Util.pm | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Raisin/Routes/Endpoint.pm b/lib/Raisin/Routes/Endpoint.pm index 8dca375..21e1c0f 100644 --- a/lib/Raisin/Routes/Endpoint.pm +++ b/lib/Raisin/Routes/Endpoint.pm @@ -51,7 +51,8 @@ sub _build_regex { "(?\.${ \$self->api_format })?"; } else { - '(?\.\w+)?'; + my $se = join '|', Raisin::Util::valid_extensions(); + "(?(?:\.(?:$se))?)?"; } }; @@ -65,7 +66,7 @@ sub _rep_regex { for ($switch) { if ($_ eq ':' || $_ eq '?') { - $r = $a . ($self->check->{$token} // '[^/.]+') . $b; + $r = $a . ($self->check->{$token} // '[^/]+?') . $b; } if ($_ eq '*') { $r = $a . '.+' . $b; diff --git a/lib/Raisin/Util.pm b/lib/Raisin/Util.pm index d32c664..a64c775 100644 --- a/lib/Raisin/Util.pm +++ b/lib/Raisin/Util.pm @@ -14,9 +14,14 @@ my %SERIALIZERS = ( text => 'text', txt => 'text', + plain => 'text', ); +sub valid_extensions { + keys %SERIALIZERS; +} + sub detect_serializer { my $type = shift; return unless $type;