public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Route matching handles slashes according to the RFC

Trailing slashes in route matching are dropped and repeated
slashes are converted to a single slash.
carllerche (author)
Mon Sep 29 16:41:04 -0700 2008
commit  32ee4fa37b534c5b046b1bb65d425947841d8e04
tree    e6dfc67c507bc1ee4bc2941c8c1b2b27f3f32b05
parent  36e76f35b62860bec3f63c30177115778586b618
...
310
311
312
313
 
 
 
 
 
314
315
316
...
310
311
312
 
313
314
315
316
317
318
319
320
0
@@ -310,7 +310,11 @@ module Merb
0
           end
0
         end
0
         
0
-        @variables = @segments.flatten.select { |s| s.is_a?(Symbol)  }
0
+        unless regexp?
0
+          @variables = @segments.flatten.select { |s| s.is_a?(Symbol)  }
1
+          compiled.gsub!(%r[/+], '/')
0
+          compiled.gsub!(%r[(.+)/$], '\1')
0
+        end
0
 
0
         compiled
0
       end
...
12
13
14
15
 
16
17
18
...
12
13
14
 
15
16
17
18
0
@@ -12,7 +12,7 @@ module Merb
0
       # ==== Returns
0
       # String:: The generated URL.
0
       def url(*args)
0
-        args << @request_params || {}
0
+        args << (@request_params || {})
0
         Merb::Router.url(*args)
0
       end
0
       
...
17
18
19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
21
22
...
232
233
234
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
235
236
237
...
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
...
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
0
@@ -17,6 +17,24 @@ describe "When recognizing requests," do
0
     it "should not match a different path" do
0
       lambda { route_to("/notinfo") }.should raise_not_found
0
     end
0
+    
0
+    it "should ignore trailing slashes" do
0
+      Merb::Router.prepare do
0
+        match("/hello/").to(:controller => "world")
0
+      end
0
+      
0
+      route_to("/hello").should have_route(:controller => "world")
0
+    end
0
+    
0
+    it "should ignore repeated slashes" do
0
+      Merb::Router.prepare do
0
+        match("/foo///bar").to(:controller => "fubar")
0
+        match("/hello//world").to(:controller => "greetings")
0
+      end
0
+      
0
+      route_to("/foo/bar").should have_route(:controller => "fubar")
0
+      route_to("/hello/world").should have_route(:controller => "greetings")
0
+    end
0
   end
0
   
0
   describe "a route with a Request method condition" do
0
@@ -232,6 +250,26 @@ describe "When recognizing requests," do
0
       lambda { route_to("/one") }.should raise_not_found
0
     end
0
     
0
+    it "should ignore trailing slashes" do
0
+      Merb::Router.prepare do
0
+        match("/hello") do
0
+          match("/").to(:controller => "greetings")
0
+        end
0
+      end
0
+      
0
+      route_to("/hello").should have_route(:controller => "greetings")
0
+    end
0
+    
0
+    it "should ignore double slashes" do
0
+      Merb::Router.prepare do
0
+        match("/hello/") do
0
+          match("/world").to(:controller => "greetings")
0
+        end
0
+      end
0
+      
0
+      route_to("/hello/world").should have_route(:controller => "greetings")
0
+    end
0
+    
0
     it "should be able to define a route and still use the context for more route definition" do
0
       Merb::Router.prepare do
0
         match("/hello") do

Comments

dkubb Mon Sep 29 20:42:45 -0700 2008 at lib/merb-core/dispatch/router/route.rb L316

It would be even simpler (and probably faster) to use String#squeeze! and String#chomp! here instead of String#gsub with a regexp, eg: compiled.squeeze!(’/’); compiled.chomp!(’/’)