Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
29030d3f
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,发现更多精彩内容 >>
提交
29030d3f
编写于
3月 15, 2013
作者:
S
Steve Klabnik
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #5606 from teohm/multipart_unicode_param_name
multipart POST - utf8 param name not encoded
上级
a662a789
b307210d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
54 addition
and
32 deletion
+54
-32
actionpack/lib/action_dispatch/http/parameters.rb
actionpack/lib/action_dispatch/http/parameters.rb
+18
-25
actionpack/lib/action_dispatch/http/request.rb
actionpack/lib/action_dispatch/http/request.rb
+2
-2
actionpack/lib/action_dispatch/http/upload.rb
actionpack/lib/action_dispatch/http/upload.rb
+4
-4
actionpack/test/dispatch/request/multipart_params_parsing_test.rb
...ck/test/dispatch/request/multipart_params_parsing_test.rb
+20
-1
actionpack/test/fixtures/multipart/bracketed_utf8_param
actionpack/test/fixtures/multipart/bracketed_utf8_param
+5
-0
actionpack/test/fixtures/multipart/single_utf8_param
actionpack/test/fixtures/multipart/single_utf8_param
+5
-0
未找到文件。
actionpack/lib/action_dispatch/http/parameters.rb
浏览文件 @
29030d3f
...
...
@@ -18,7 +18,7 @@ def parameters
query_parameters
.
dup
end
params
.
merge!
(
path_parameters
)
encode_params
(
params
)
.
with_indifferent_access
params
.
with_indifferent_access
end
end
alias
:params
:parameters
...
...
@@ -50,40 +50,33 @@ def reset_parameters #:nodoc:
private
# Convert nested Hash to HashWithIndifferentAccess
# and UTF-8 encode both keys and values in nested Hash.
#
# TODO: Validate that the characters are UTF-8. If they aren't,
# you'll get a weird error down the road, but our form handling
# should really prevent that from happening
def
encode_params
(
params
)
def
normalize_
encode_params
(
params
)
if
params
.
is_a?
(
String
)
return
params
.
force_encoding
(
Encoding
::
UTF_8
).
encode!
elsif
!
params
.
is_a?
(
Hash
)
return
params
end
params
.
each_value
do
|
v
|
case
v
when
Hash
encode_params
(
v
)
when
Array
v
.
map!
{
|
el
|
encode_params
(
el
)
}
else
encode_params
(
v
)
end
end
end
# Convert nested Hash to ActiveSupport::HashWithIndifferentAccess
def
normalize_parameters
(
value
)
case
value
when
Hash
h
=
{}
value
.
each
{
|
k
,
v
|
h
[
k
]
=
normalize_parameters
(
v
)
}
h
.
with_indifferent_access
when
Array
value
.
map
{
|
e
|
normalize_parameters
(
e
)
}
else
value
new_hash
=
{}
params
.
each
do
|
k
,
v
|
new_key
=
k
.
is_a?
(
String
)
?
k
.
dup
.
force_encoding
(
"UTF-8"
).
encode!
:
k
new_hash
[
new_key
]
=
case
v
when
Hash
normalize_encode_params
(
v
)
when
Array
v
.
map!
{
|
el
|
normalize_encode_params
(
el
)
}
else
normalize_encode_params
(
v
)
end
end
new_hash
.
with_indifferent_access
end
end
end
...
...
actionpack/lib/action_dispatch/http/request.rb
浏览文件 @
29030d3f
...
...
@@ -273,7 +273,7 @@ def session_options=(options)
# Override Rack's GET method to support indifferent access
def
GET
@env
[
"action_dispatch.request.query_parameters"
]
||=
(
normalize_
parameter
s
(
super
)
||
{})
@env
[
"action_dispatch.request.query_parameters"
]
||=
(
normalize_
encode_param
s
(
super
)
||
{})
rescue
TypeError
=>
e
raise
ActionController
::
BadRequest
.
new
(
:query
,
e
)
end
...
...
@@ -281,7 +281,7 @@ def GET
# Override Rack's POST method to support indifferent access
def
POST
@env
[
"action_dispatch.request.request_parameters"
]
||=
(
normalize_
parameter
s
(
super
)
||
{})
@env
[
"action_dispatch.request.request_parameters"
]
||=
(
normalize_
encode_param
s
(
super
)
||
{})
rescue
TypeError
=>
e
raise
ActionController
::
BadRequest
.
new
(
:request
,
e
)
end
...
...
actionpack/lib/action_dispatch/http/upload.rb
浏览文件 @
29030d3f
...
...
@@ -75,16 +75,16 @@ def encode_filename(filename)
end
module
Upload
# :nodoc:
#
Convert nested Hash to ActiveSupport::HashWithIndifferentAccess and replace
#
file upload hash with UploadedFile objects
def
normalize_
parameter
s
(
value
)
#
Replace file upload hash with UploadedFile objects
#
when normalize and encode parameters.
def
normalize_
encode_param
s
(
value
)
if
Hash
===
value
&&
value
.
has_key?
(
:tempfile
)
UploadedFile
.
new
(
value
)
else
super
end
end
private
:normalize_
parameter
s
private
:normalize_
encode_param
s
end
end
end
actionpack/test/dispatch/request/multipart_params_parsing_test.rb
浏览文件 @
29030d3f
# encoding: utf-8
require
'abstract_unit'
class
MultipartParamsParsingTest
<
ActionDispatch
::
IntegrationTest
class
TestController
<
ActionController
::
Base
class
<<
self
attr_accessor
:last_request_parameters
attr_accessor
:last_request_parameters
,
:last_parameters
end
def
parse
self
.
class
.
last_request_parameters
=
request
.
request_parameters
self
.
class
.
last_parameters
=
request
.
parameters
head
:ok
end
...
...
@@ -30,6 +32,23 @@ def teardown
assert_equal
({
'foo'
=>
{
'baz'
=>
'bar'
}},
parse_multipart
(
'bracketed_param'
))
end
test
"parse single utf8 parameter"
do
assert_equal
({
'Iñtërnâtiônàlizætiøn_name'
=>
'Iñtërnâtiônàlizætiøn_value'
},
parse_multipart
(
'single_utf8_param'
),
"request.request_parameters"
)
assert_equal
(
'Iñtërnâtiônàlizætiøn_value'
,
TestController
.
last_parameters
[
'Iñtërnâtiônàlizætiøn_name'
],
"request.parameters"
)
end
test
"parse bracketed utf8 parameter"
do
assert_equal
({
'Iñtërnâtiônàlizætiøn_name'
=>
{
'Iñtërnâtiônàlizætiøn_nested_name'
=>
'Iñtërnâtiônàlizætiøn_value'
}
},
parse_multipart
(
'bracketed_utf8_param'
),
"request.request_parameters"
)
assert_equal
(
{
'Iñtërnâtiônàlizætiøn_nested_name'
=>
'Iñtërnâtiônàlizætiøn_value'
},
TestController
.
last_parameters
[
'Iñtërnâtiônàlizætiøn_name'
],
"request.parameters"
)
end
test
"parses text file"
do
params
=
parse_multipart
(
'text_file'
)
assert_equal
%w(file foo)
,
params
.
keys
.
sort
...
...
actionpack/test/fixtures/multipart/bracketed_utf8_param
0 → 100644
浏览文件 @
29030d3f
--AaB03x
Content-Disposition: form-data; name="Iñtërnâtiônàlizætiøn_name[Iñtërnâtiônàlizætiøn_nested_name]"
Iñtërnâtiônàlizætiøn_value
--AaB03x--
actionpack/test/fixtures/multipart/single_utf8_param
0 → 100644
浏览文件 @
29030d3f
--AaB03x
Content-Disposition: form-data; name="Iñtërnâtiônàlizætiøn_name"
Iñtërnâtiônàlizætiøn_value
--AaB03x--
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录