Allow dots in path matchers, so that sub (/foo.html) works
Andrew Rodland [Fri, 23 Dec 2011 05:02:30 +0000 (00:02 -0500)]
lib/Web/Dispatch/Parser.pm
t/dispatch_parser.t

index 6ebc51e..bd62652 100644 (file)
@@ -165,7 +165,7 @@ sub _url_path_segment_match {
     /\G(?:(?=[+|\)])|$)/gc and
       return '';
     # word chars only -> exact path part match
-    /\G([\w\-]+)/gc and
+    /\G([\w\-.]+)/gc and
       return "\Q$1";
     # ** -> capture unlimited path parts
     /\G\*\*/gc and
index 8b7966e..b1bc859 100644 (file)
@@ -254,6 +254,28 @@ my $dp = Web::Dispatch::Parser->new;
 }
 
 {
+  my $ext = $dp->parse('/foo.bar');
+
+  is_deeply(
+    [ $ext->({ PATH_INFO => '/foo.bar' }) ],
+    [ {} ],
+    '/foo.bar matches /foo.bar'
+  );
+
+  is_deeply(
+    [ $ext->({ PATH_INFO => '/foo.bar.ext' }) ],
+    [ {} ],
+    '/foo.bar matches /foo.bar.ext'
+  );
+
+  is_deeply(
+    [ $ext->({ PATH_INFO => '/foo.notbar' }) ],
+    [],
+    '/foo.bar does not match /foo.notbar'
+  );
+}
+
+{
   my $sub = $dp->parse('/foo/*/...');
 
   is_deeply(