http_router 0.3.14 → 0.3.15
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/http_router/node.rb +4 -9
- data/lib/http_router/version.rb +1 -1
- data/spec/recognize_spec.rb +10 -0
- metadata +4 -4
data/lib/http_router/node.rb
CHANGED
@@ -136,7 +136,9 @@ class HttpRouter
|
|
136
136
|
|
137
137
|
def find_on_parts(request, parts, params)
|
138
138
|
if parts and !parts.empty?
|
139
|
-
|
139
|
+
if potential = potential_match(request, parts, params)
|
140
|
+
return potential
|
141
|
+
end
|
140
142
|
if @linear && !@linear.empty?
|
141
143
|
response = nil
|
142
144
|
dupped_parts = nil
|
@@ -196,14 +198,7 @@ class HttpRouter
|
|
196
198
|
end
|
197
199
|
|
198
200
|
def potential_match(request, parts, params)
|
199
|
-
|
200
|
-
potential = find_on_parts(request, [], params)
|
201
|
-
if potential and (router.ignore_trailing_slash? or potential.value && potential.value.route.trailing_slash_ignore?)
|
202
|
-
parts.shift
|
203
|
-
potential
|
204
|
-
end
|
205
|
-
end
|
206
|
-
nil
|
201
|
+
parts.size == 1 and parts.first == '' and potential = find_on_parts(request, nil, params) and (router.ignore_trailing_slash? or (potential.value and potential.value.route.trailing_slash_ignore?)) and parts.shift ? potential : nil
|
207
202
|
end
|
208
203
|
end
|
209
204
|
|
data/lib/http_router/version.rb
CHANGED
data/spec/recognize_spec.rb
CHANGED
@@ -109,10 +109,20 @@ describe "HttpRouter#recognize" do
|
|
109
109
|
route = @router.add("/test").to(:test)
|
110
110
|
@router.recognize(Rack::MockRequest.env_for('/test/')).should be_nil
|
111
111
|
end
|
112
|
+
|
112
113
|
it "should not capture normally" do
|
113
114
|
route = @router.add("/:test").to(:test)
|
114
115
|
@router.recognize(Rack::MockRequest.env_for('/test/')).params.first.should == 'test'
|
115
116
|
end
|
117
|
+
|
118
|
+
it "should recognize trailing slashes when there are other more specific routes near by" do
|
119
|
+
@router = HttpRouter.new
|
120
|
+
route = @router.add("/foo").to(:foo)
|
121
|
+
route = @router.add("/foo/:bar/:id").to(:foo_bar)
|
122
|
+
@router.recognize(Rack::MockRequest.env_for('/foo')).dest.should == :foo
|
123
|
+
@router.recognize(Rack::MockRequest.env_for('/foo/')).dest.should == :foo
|
124
|
+
@router.recognize(Rack::MockRequest.env_for('/foo/5/10')).dest.should == :foo_bar
|
125
|
+
end
|
116
126
|
end
|
117
127
|
end
|
118
128
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 15
|
10
|
+
version: 0.3.15
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Joshua Hull
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-09-
|
18
|
+
date: 2010-09-03 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|