Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f48e8993
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,体验更适合开发者的 AI 搜索 >>
提交
f48e8993
编写于
5月 01, 2008
作者:
T
Tobias Lütke
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Accept header mime parser can now deal with empty fields
上级
f122ca58
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
13 addition
and
3 deletion
+13
-3
actionpack/lib/action_controller/mime_type.rb
actionpack/lib/action_controller/mime_type.rb
+6
-3
actionpack/test/controller/mime_type_test.rb
actionpack/test/controller/mime_type_test.rb
+7
-0
未找到文件。
actionpack/lib/action_controller/mime_type.rb
浏览文件 @
f48e8993
...
...
@@ -71,8 +71,11 @@ def parse(accept_header)
# keep track of creation order to keep the subsequent sort stable
list
=
[]
accept_header
.
split
(
/,/
).
each_with_index
do
|
header
,
index
|
params
=
header
.
split
(
/;\s*q=/
)
list
<<
AcceptItem
.
new
(
index
,
*
params
)
unless
params
.
empty?
params
,
q
=
header
.
split
(
/;\s*q=/
)
if
params
params
.
strip!
list
<<
AcceptItem
.
new
(
index
,
params
,
q
)
unless
params
.
empty?
end
end
list
.
sort!
...
...
@@ -145,7 +148,7 @@ def ===(list)
end
def
==
(
mime_type
)
return
false
unless
mime_type
return
false
if
mime_type
.
blank?
(
@synonyms
+
[
self
]).
any?
do
|
synonym
|
synonym
.
to_s
==
mime_type
.
to_s
||
synonym
.
to_sym
==
mime_type
.
to_sym
end
...
...
actionpack/test/controller/mime_type_test.rb
浏览文件 @
f48e8993
...
...
@@ -28,6 +28,13 @@ def test_parse_crappy_broken_acceptlines
expect
=
[
Mime
::
HTML
,
Mime
::
XML
,
"image/*"
,
Mime
::
TEXT
,
Mime
::
ALL
]
assert_equal
expect
,
Mime
::
Type
.
parse
(
accept
).
collect
{
|
c
|
c
.
to_s
}
end
# Accept header send with user HTTP_USER_AGENT: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; InfoPath.1)
def
test_parse_crappy_broken_acceptlines2
accept
=
"image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, , pronto/1.00.00, sslvpn/1.00.00.00, */*"
expect
=
[
'image/gif'
,
'image/x-xbitmap'
,
'image/jpeg'
,
'image/pjpeg'
,
'application/x-shockwave-flash'
,
'application/vnd.ms-excel'
,
'application/vnd.ms-powerpoint'
,
'application/msword'
,
'pronto/1.00.00'
,
'sslvpn/1.00.00.00'
,
Mime
::
ALL
]
assert_equal
expect
,
Mime
::
Type
.
parse
(
accept
).
collect
{
|
c
|
c
.
to_s
}
end
def
test_custom_type
Mime
::
Type
.
register
(
"image/gif"
,
:gif
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录