Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b866be16
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,发现更多精彩内容 >>
提交
b866be16
编写于
7月 14, 2016
作者:
A
Aaron Patterson
提交者:
GitHub
7月 14, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #25816 from greysteil/check-path-param-encoding
Check `request.path_parameters` encoding at the point they're set
上级
ea31bdd7
9f38a3fb
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
29 deletion
+35
-29
actionpack/CHANGELOG.md
actionpack/CHANGELOG.md
+10
-0
actionpack/lib/action_dispatch/http/parameters.rb
actionpack/lib/action_dispatch/http/parameters.rb
+7
-0
actionpack/lib/action_dispatch/http/request.rb
actionpack/lib/action_dispatch/http/request.rb
+0
-12
actionpack/lib/action_dispatch/routing/redirection.rb
actionpack/lib/action_dispatch/routing/redirection.rb
+0
-1
actionpack/test/dispatch/request_test.rb
actionpack/test/dispatch/request_test.rb
+3
-7
actionpack/test/dispatch/routing_test.rb
actionpack/test/dispatch/routing_test.rb
+15
-9
未找到文件。
actionpack/CHANGELOG.md
浏览文件 @
b866be16
*
Check
`request.path_parameters`
encoding at the point they're set
Check for any non-UTF8 characters in path parameters at the point they're
set in `env`. Previously they were checked for when used to get a controller
class, but this meant routes that went directly to a Rack app, or skipped
controller instantiation for some other reason, had to defend against
non-UTF8 characters themselves.
*Grey Baker*
*
Don't raise ActionController::UnknownHttpMethod from ActionDispatch::Static
Pass `Rack::Request` objects to `ActionDispatch::FileHandler` to avoid it
...
...
actionpack/lib/action_dispatch/http/parameters.rb
浏览文件 @
b866be16
...
...
@@ -44,7 +44,14 @@ def parameters
def
path_parameters
=
(
parameters
)
#:nodoc:
delete_header
(
'action_dispatch.request.parameters'
)
# If any of the path parameters has an invalid encoding then
# raise since it's likely to trigger errors further on.
Request
::
Utils
.
check_param_encoding
(
parameters
)
set_header
PARAMETERS_KEY
,
parameters
rescue
Rack
::
Utils
::
ParameterTypeError
,
Rack
::
Utils
::
InvalidParameterError
=>
e
raise
ActionController
::
BadRequest
.
new
(
"Invalid path parameters:
#{
e
.
message
}
"
)
end
# Returns a hash with the \parameters used to form the \path of the request.
...
...
actionpack/lib/action_dispatch/http/request.rb
浏览文件 @
b866be16
...
...
@@ -66,24 +66,12 @@ def initialize(env)
def
commit_cookie_jar!
# :nodoc:
end
def
check_path_parameters!
# If any of the path parameters has an invalid encoding then
# raise since it's likely to trigger errors further on.
path_parameters
.
each
do
|
key
,
value
|
next
unless
value
.
respond_to?
(
:valid_encoding?
)
unless
value
.
valid_encoding?
raise
ActionController
::
BadRequest
,
"Invalid parameter encoding:
#{
key
}
=>
#{
value
.
inspect
}
"
end
end
end
PASS_NOT_FOUND
=
Class
.
new
{
# :nodoc:
def
self
.
action
(
_
);
self
;
end
def
self
.
call
(
_
);
[
404
,
{
'X-Cascade'
=>
'pass'
},
[]];
end
}
def
controller_class
check_path_parameters!
params
=
path_parameters
if
params
.
key?
(
:controller
)
...
...
actionpack/lib/action_dispatch/routing/redirection.rb
浏览文件 @
b866be16
...
...
@@ -22,7 +22,6 @@ def call(env)
end
def
serve
(
req
)
req
.
check_path_parameters!
uri
=
URI
.
parse
(
path
(
req
.
path_parameters
,
req
))
unless
uri
.
host
...
...
actionpack/test/dispatch/request_test.rb
浏览文件 @
b866be16
...
...
@@ -1018,17 +1018,13 @@ class RequestParameters < BaseRequestTest
end
test
"path parameters with invalid UTF8 encoding"
do
request
=
stub_request
(
"action_dispatch.request.path_parameters"
=>
{
foo:
"
\xBE
"
}
)
request
=
stub_request
err
=
assert_raises
(
ActionController
::
BadRequest
)
do
request
.
check_path_parameters!
request
.
path_parameters
=
{
foo:
"
\xBE
"
}
end
assert_match
"Invalid parameter encoding"
,
err
.
message
assert_match
"foo"
,
err
.
message
assert_match
"
\\
xBE"
,
err
.
message
assert_equal
"Invalid path parameters: Non UTF-8 value:
\xBE
"
,
err
.
message
end
test
"parameters not accessible after rack parse error of invalid UTF8 character"
do
...
...
actionpack/test/dispatch/routing_test.rb
浏览文件 @
b866be16
...
...
@@ -4331,15 +4331,16 @@ def show
test
"invalid UTF-8 encoding returns a 400 Bad Request"
do
with_routing
do
|
set
|
ActiveSupport
::
Deprecation
.
silence
do
set
.
draw
do
get
"/bar/:id"
,
:to
=>
redirect
(
"/foo/show/%{id}"
)
get
"/foo/show(/:id)"
,
:to
=>
"test_invalid_urls/foo#show"
set
.
draw
do
get
"/bar/:id"
,
:to
=>
redirect
(
"/foo/show/%{id}"
)
get
"/foo/show(/:id)"
,
:to
=>
"test_invalid_urls/foo#show"
ActiveSupport
::
Deprecation
.
silence
do
get
"/foo(/:action(/:id))"
,
:controller
=>
"test_invalid_urls/foo"
get
"/:controller(/:action(/:id))"
end
ok
=
lambda
{
|
env
|
[
200
,
{
'Content-Type'
=>
'text/plain'
},
[]]
}
get
'/foobar/:id'
,
to:
ok
ActiveSupport
::
Deprecation
.
silence
do
get
"/foo(/:action(/:id))"
,
:controller
=>
"test_invalid_urls/foo"
get
"/:controller(/:action(/:id))"
end
end
...
...
@@ -4354,6 +4355,9 @@ def show
get
"/bar/%E2%EF%BF%BD%A6"
assert_response
:bad_request
get
"/foobar/%E2%EF%BF%BD%A6"
assert_response
:bad_request
end
end
end
...
...
@@ -4774,7 +4778,9 @@ class TestPathParameters < ActionDispatch::IntegrationTest
end
end
get
':controller(/:action/(:id))'
ActiveSupport
::
Deprecation
.
silence
do
get
':controller(/:action/(:id))'
end
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录