fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-02-28 02:27 pm

[dw-free] Make automatic /foo/ == /foo/index work on '/index'

[commit: http://hg.dwscoalition.org/dw-free/rev/e611a6c5f796]

http://bugs.dwscoalition.org/show_bug.cgi?id=3549

Allow mapping to /index, for the main page, work, even if there is no
subpath (that is, given a regisetred mapping of /foo/index, all of /foo,
/foo/, /foo/index would have pulled up the correct page. This makes it work
for the root /index)

Patch by [personal profile] exor674.

Files modified:
  • cgi-bin/DW/Routing.pm
  • t/routing-indexes.t
--------------------------------------------------------------------------------
diff -r 730e3853d609 -r e611a6c5f796 cgi-bin/DW/Routing.pm
--- a/cgi-bin/DW/Routing.pm	Mon Feb 28 22:10:54 2011 +0800
+++ b/cgi-bin/DW/Routing.pm	Mon Feb 28 22:27:04 2011 +0800
@@ -312,7 +312,7 @@ sub register_string {
     $string_choices{'ssl'  . $string} = $hash if $hash->{ssl};
     $string_choices{'user' . $string} = $hash if $hash->{user};
 
-    if ( $string =~ m!(^(.+)/)index$! && ! exists $opts{no_redirects} ) {
+    if ( $string =~ m!(^(.*)/)index$! && ! exists $opts{no_redirects} ) {
         my %opts = (
             app => $hash->{app},
             ssl => $hash->{ssl},
@@ -321,7 +321,7 @@ sub register_string {
             format => $hash->{format},
             no_redirects => 1,
         );
-        $class->register_redirect( $2, $1, %opts );
+        $class->register_redirect( $2, $1, %opts ) if $2;
         $string_choices{'app'  . $1} = $hash if $hash->{app};
         $string_choices{'ssl'  . $1} = $hash if $hash->{ssl};
         $string_choices{'user' . $1} = $hash if $hash->{user};
diff -r 730e3853d609 -r e611a6c5f796 t/routing-indexes.t
--- a/t/routing-indexes.t	Mon Feb 28 22:10:54 2011 +0800
+++ b/t/routing-indexes.t	Mon Feb 28 22:27:04 2011 +0800
@@ -33,10 +33,6 @@ handle_redirect( '/xx3', '/xx3/' );
 
 DW::Routing->register_string( "/index", \&handler, app => 1, args => "it_worked_redir" );
 
-TODO: {
-      local $TODO = "This doesn't acutally work yet";
-
-      handle_request( "/" , "/", 1, "it_worked_redir" );
-};
+handle_request( "/" , "/", 1, "it_worked_redir" );
 handle_request( "/index" , "/index", 1, "it_worked_redir" );
 # 5
--------------------------------------------------------------------------------