Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
fd132d0d
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
fd132d0d
编写于
7月 12, 2018
作者:
R
Rafael França
提交者:
GitHub
7月 12, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #33341 from Edouard-chin/ec-fix-to-param
e4e1b620
broke `to_param` handling:
上级
0d864e7e
48b6bacb
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
35 addition
and
5 deletion
+35
-5
actionpack/lib/action_controller/test_case.rb
actionpack/lib/action_controller/test_case.rb
+1
-1
actionpack/test/controller/test_case_test.rb
actionpack/test/controller/test_case_test.rb
+15
-2
activesupport/lib/active_support/core_ext/object/to_query.rb
activesupport/lib/active_support/core_ext/object/to_query.rb
+5
-2
activesupport/test/core_ext/object/to_query_test.rb
activesupport/test/core_ext/object/to_query_test.rb
+14
-0
未找到文件。
actionpack/lib/action_controller/test_case.rb
浏览文件 @
fd132d0d
...
@@ -109,7 +109,7 @@ def assign_parameters(routes, controller_path, action, parameters, generated_pat
...
@@ -109,7 +109,7 @@ def assign_parameters(routes, controller_path, action, parameters, generated_pat
when
:xml
when
:xml
data
=
non_path_parameters
.
to_xml
data
=
non_path_parameters
.
to_xml
when
:url_encoded_form
when
:url_encoded_form
data
=
Rack
::
Utils
.
build_nested_query
(
non_path_parameters
)
data
=
non_path_parameters
.
to_query
else
else
@custom_param_parsers
[
content_mime_type
.
symbol
]
=
->
(
_
)
{
non_path_parameters
}
@custom_param_parsers
[
content_mime_type
.
symbol
]
=
->
(
_
)
{
non_path_parameters
}
data
=
non_path_parameters
.
to_query
data
=
non_path_parameters
.
to_query
...
...
actionpack/test/controller/test_case_test.rb
浏览文件 @
fd132d0d
...
@@ -220,7 +220,7 @@ def test_raw_post_handling
...
@@ -220,7 +220,7 @@ def test_raw_post_handling
params
=
Hash
[
:page
,
{
name:
"page name"
},
"some key"
,
123
]
params
=
Hash
[
:page
,
{
name:
"page name"
},
"some key"
,
123
]
post
:render_raw_post
,
params:
params
.
dup
post
:render_raw_post
,
params:
params
.
dup
assert_equal
Rack
::
Utils
.
build_nested_query
(
params
)
,
@response
.
body
assert_equal
params
.
to_query
,
@response
.
body
end
end
def
test_params_round_trip
def
test_params_round_trip
...
@@ -231,12 +231,25 @@ def test_params_round_trip
...
@@ -231,12 +231,25 @@ def test_params_round_trip
assert_equal
params
.
merge
(
controller_info
),
JSON
.
parse
(
@response
.
body
)
assert_equal
params
.
merge
(
controller_info
),
JSON
.
parse
(
@response
.
body
)
end
end
def
test_handle_to_params
klass
=
Class
.
new
do
def
to_param
"bar"
end
end
post
:test_params
,
params:
{
foo:
klass
.
new
}
assert_equal
JSON
.
parse
(
@response
.
body
)[
"foo"
],
"bar"
end
def
test_body_stream
def
test_body_stream
params
=
Hash
[
:page
,
{
name:
"page name"
},
"some key"
,
123
]
params
=
Hash
[
:page
,
{
name:
"page name"
},
"some key"
,
123
]
post
:render_body
,
params:
params
.
dup
post
:render_body
,
params:
params
.
dup
assert_equal
Rack
::
Utils
.
build_nested_query
(
params
)
,
@response
.
body
assert_equal
params
.
to_query
,
@response
.
body
end
end
def
test_document_body_and_params_with_post
def
test_document_body_and_params_with_post
...
...
activesupport/lib/active_support/core_ext/object/to_query.rb
浏览文件 @
fd132d0d
...
@@ -75,11 +75,14 @@ class Hash
...
@@ -75,11 +75,14 @@ class Hash
#
#
# This method is also aliased as +to_param+.
# This method is also aliased as +to_param+.
def
to_query
(
namespace
=
nil
)
def
to_query
(
namespace
=
nil
)
collect
do
|
key
,
value
|
query
=
collect
do
|
key
,
value
|
unless
(
value
.
is_a?
(
Hash
)
||
value
.
is_a?
(
Array
))
&&
value
.
empty?
unless
(
value
.
is_a?
(
Hash
)
||
value
.
is_a?
(
Array
))
&&
value
.
empty?
value
.
to_query
(
namespace
?
"
#{
namespace
}
[
#{
key
}
]"
:
key
)
value
.
to_query
(
namespace
?
"
#{
namespace
}
[
#{
key
}
]"
:
key
)
end
end
end
.
compact
.
sort!
*
"&"
end
.
compact
query
.
sort!
unless
namespace
.
to_s
.
include?
(
"[]"
)
query
.
join
(
"&"
)
end
end
alias_method
:to_param
,
:to_query
alias_method
:to_param
,
:to_query
...
...
activesupport/test/core_ext/object/to_query_test.rb
浏览文件 @
fd132d0d
...
@@ -77,6 +77,20 @@ def test_hash_sorted_lexicographically
...
@@ -77,6 +77,20 @@ def test_hash_sorted_lexicographically
assert_equal
"name=Nakshay&type=human"
,
hash
.
to_query
assert_equal
"name=Nakshay&type=human"
,
hash
.
to_query
end
end
def
test_hash_not_sorted_lexicographically_for_nested_structure
params
=
{
"foo"
=>
{
"contents"
=>
[
{
"name"
=>
"gorby"
,
"id"
=>
"123"
},
{
"name"
=>
"puff"
,
"d"
=>
"true"
}
]
}
}
expected
=
"foo[contents][][name]=gorby&foo[contents][][id]=123&foo[contents][][name]=puff&foo[contents][][d]=true"
assert_equal
expected
,
URI
.
decode
(
params
.
to_query
)
end
private
private
def
assert_query_equal
(
expected
,
actual
)
def
assert_query_equal
(
expected
,
actual
)
assert_equal
expected
.
split
(
"&"
),
actual
.
to_query
.
split
(
"&"
)
assert_equal
expected
.
split
(
"&"
),
actual
.
to_query
.
split
(
"&"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录