gin 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/History.rdoc +6 -1
- data/lib/gin.rb +1 -1
- data/lib/gin/router.rb +5 -4
- data/test/test_router.rb +31 -0
- data/test/test_test.rb +2 -2
- metadata +2 -2
data/History.rdoc
CHANGED
data/lib/gin.rb
CHANGED
data/lib/gin/router.rb
CHANGED
@@ -152,8 +152,9 @@ class Gin::Router
|
|
152
152
|
def to_path params={}
|
153
153
|
rendered_path = @path.dup
|
154
154
|
rendered_path = rendered_path % @param_keys.map do |k|
|
155
|
-
params.delete(k) || params.delete(k.to_sym)
|
156
|
-
|
155
|
+
val = params.delete(k) || params.delete(k.to_sym)
|
156
|
+
raise(PathArgumentError, "Missing param #{k}") unless val
|
157
|
+
CGI.escape(val.to_s)
|
157
158
|
end unless @param_keys.empty?
|
158
159
|
|
159
160
|
rendered_path << "?#{Gin.build_query(params)}" unless params.empty?
|
@@ -326,10 +327,10 @@ class Gin::Router
|
|
326
327
|
curr_node = curr_node[key]
|
327
328
|
|
328
329
|
elsif curr_node["%s"]
|
329
|
-
param_vals << key
|
330
|
+
param_vals << CGI.unescape(key)
|
330
331
|
curr_node = curr_node["%s"]
|
331
332
|
|
332
|
-
elsif child_and_matches = curr_node.match(key)
|
333
|
+
elsif child_and_matches = curr_node.match(CGI.unescape(key))
|
333
334
|
param_vals.concat child_and_matches[1]
|
334
335
|
curr_node = child_and_matches[0]
|
335
336
|
|
data/test/test_router.rb
CHANGED
@@ -38,6 +38,26 @@ class RouterTest < Test::Unit::TestCase
|
|
38
38
|
end
|
39
39
|
|
40
40
|
|
41
|
+
def test_add_and_retrieve_cgi_escaped
|
42
|
+
@router.add MyCtrl, '/my_ctrl' do
|
43
|
+
get :bar, "/bar/:id"
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_equal [MyCtrl, :bar, {'id' => '123 456'}],
|
47
|
+
@router.resources_for("GET", "/my_ctrl/bar/123+456")
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def test_add_and_retrieve_complex_cgi_escaped
|
52
|
+
@router.add MyCtrl, '/my_ctrl' do
|
53
|
+
get :bar, "/bar/:type/:id.:format"
|
54
|
+
end
|
55
|
+
|
56
|
+
assert_equal [MyCtrl, :bar, {"type"=>"[I]", "id"=>"123 456", "format"=>"json"}],
|
57
|
+
@router.resources_for("GET", "/my_ctrl/bar/%5BI%5D/123+456.json")
|
58
|
+
end
|
59
|
+
|
60
|
+
|
41
61
|
def test_add_and_retrieve_named_route
|
42
62
|
@router.add FooController, "/foo" do
|
43
63
|
get :index, "/", :all_foo
|
@@ -240,4 +260,15 @@ class RouterTest < Test::Unit::TestCase
|
|
240
260
|
@router.path_to(MyCtrl, :bar, params)
|
241
261
|
end
|
242
262
|
end
|
263
|
+
|
264
|
+
|
265
|
+
def test_path_to_complex_param_cgi_escaped
|
266
|
+
@router.add MyCtrl, "/" do
|
267
|
+
get :bar, "/bar/:type/:id.:format"
|
268
|
+
end
|
269
|
+
|
270
|
+
params = {'type' => 'sub/thing', 'id' => '123&4', 'more' => 'hi there', 'format' => 'json'}
|
271
|
+
assert_equal "/bar/sub%2Fthing/123%264.json?more=hi+there",
|
272
|
+
@router.path_to(MyCtrl, :bar, params)
|
273
|
+
end
|
243
274
|
end
|
data/test/test_test.rb
CHANGED
@@ -76,9 +76,9 @@ class TestTest < Test::Unit::TestCase
|
|
76
76
|
|
77
77
|
def test_make_request
|
78
78
|
resp = @tests.make_request :get, :show_bar,
|
79
|
-
{id: 123, foo: "BAR", bar: "BAZ"},'REMOTE_ADDR' => '127.0.0.1'
|
79
|
+
{id: 123, foo: "BAR", bar: "BAZ Foo"},'REMOTE_ADDR' => '127.0.0.1'
|
80
80
|
|
81
|
-
assert_equal "foo=BAR&bar=BAZ", @tests.req_env['QUERY_STRING']
|
81
|
+
assert_equal "foo=BAR&bar=BAZ+Foo", @tests.req_env['QUERY_STRING']
|
82
82
|
assert_equal "/bar/123", @tests.req_env['PATH_INFO']
|
83
83
|
assert_equal "127.0.0.1", @tests.req_env['REMOTE_ADDR']
|
84
84
|
assert_equal "127.0.0.1", @tests.request.ip
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -225,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
225
|
version: '0'
|
226
226
|
segments:
|
227
227
|
- 0
|
228
|
-
hash:
|
228
|
+
hash: 3379788584365895606
|
229
229
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
230
230
|
none: false
|
231
231
|
requirements:
|