Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b4330932
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,发现更多精彩内容 >>
提交
b4330932
编写于
5月 19, 2008
作者:
J
Jeremy Kemper
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Ruby 1.9 compat: ensure binary encoding for post body parsing
上级
b5c8433a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
40 addition
and
17 deletion
+40
-17
actionpack/lib/action_controller/cgi_ext/stdinput.rb
actionpack/lib/action_controller/cgi_ext/stdinput.rb
+1
-0
actionpack/lib/action_controller/cgi_process.rb
actionpack/lib/action_controller/cgi_process.rb
+1
-0
actionpack/lib/action_controller/integration.rb
actionpack/lib/action_controller/integration.rb
+4
-0
actionpack/lib/action_controller/request.rb
actionpack/lib/action_controller/request.rb
+17
-11
actionpack/lib/action_controller/test_process.rb
actionpack/lib/action_controller/test_process.rb
+2
-1
actionpack/test/controller/test_test.rb
actionpack/test/controller/test_test.rb
+15
-5
未找到文件。
actionpack/lib/action_controller/cgi_ext/stdinput.rb
浏览文件 @
b4330932
...
...
@@ -16,6 +16,7 @@ def self.included(base)
def
initialize_with_stdinput
(
type
=
nil
,
stdinput
=
$stdin
)
@stdinput
=
stdinput
@stdinput
.
set_encoding
(
Encoding
::
BINARY
)
if
@stdinput
.
respond_to?
(
:set_encoding
)
initialize_without_stdinput
(
type
||
'query'
)
end
end
...
...
actionpack/lib/action_controller/cgi_process.rb
浏览文件 @
b4330932
...
...
@@ -65,6 +65,7 @@ def query_string
# variable is already set, wrap it in a StringIO.
def
body
if
raw_post
=
env
[
'RAW_POST_DATA'
]
raw_post
.
force_encoding
(
Encoding
::
BINARY
)
if
raw_post
.
respond_to?
(
:force_encoding
)
StringIO
.
new
(
raw_post
)
else
@cgi
.
stdinput
...
...
actionpack/lib/action_controller/integration.rb
浏览文件 @
b4330932
...
...
@@ -228,6 +228,8 @@ def initialize(env, stdinput = nil)
super
stdinput
.
set_encoding
(
Encoding
::
BINARY
)
if
stdinput
.
respond_to?
(
:set_encoding
)
stdinput
.
force_encoding
(
Encoding
::
BINARY
)
if
stdinput
.
respond_to?
(
:force_encoding
)
@stdinput
=
stdinput
.
is_a?
(
IO
)
?
stdinput
:
StringIO
.
new
(
stdinput
||
''
)
end
end
...
...
@@ -382,6 +384,8 @@ def multipart_body(params, boundary)
multipart_requestify
(
params
).
map
do
|
key
,
value
|
if
value
.
respond_to?
(
:original_filename
)
File
.
open
(
value
.
path
)
do
|
f
|
f
.
set_encoding
(
Encoding
::
BINARY
)
if
f
.
respond_to?
(
:set_encoding
)
<<-
EOF
--
#{
boundary
}
\r
Content-Disposition: form-data; name="
#{
key
}
"; filename="
#{
CGI
.
escape
(
value
.
original_filename
)
}
"
\r
...
...
actionpack/lib/action_controller/request.rb
浏览文件 @
b4330932
...
...
@@ -466,8 +466,8 @@ def parse_request_parameters(params)
parser
.
result
end
def
parse_multipart_form_parameters
(
body
,
boundary
,
content_length
,
env
)
parse_request_parameters
(
read_multipart
(
body
,
boundary
,
content_length
,
env
))
def
parse_multipart_form_parameters
(
body
,
boundary
,
body_size
,
env
)
parse_request_parameters
(
read_multipart
(
body
,
boundary
,
body_size
,
env
))
end
def
extract_multipart_boundary
(
content_type_with_parameters
)
...
...
@@ -519,7 +519,7 @@ def get_typed_value(value)
EOL
=
"
\015\012
"
def
read_multipart
(
body
,
boundary
,
content_length
,
env
)
def
read_multipart
(
body
,
boundary
,
body_size
,
env
)
params
=
Hash
.
new
([])
boundary
=
"--"
+
boundary
quoted_boundary
=
Regexp
.
quote
(
boundary
)
...
...
@@ -529,8 +529,14 @@ def read_multipart(body, boundary, content_length, env)
# start multipart/form-data
body
.
binmode
if
defined?
body
.
binmode
case
body
when
File
body
.
set_encoding
(
Encoding
::
BINARY
)
if
body
.
respond_to?
(
:set_encoding
)
when
StringIO
body
.
string
.
force_encoding
(
Encoding
::
BINARY
)
if
body
.
string
.
respond_to?
(
:force_encoding
)
end
boundary_size
=
boundary
.
size
+
EOL
.
size
content_length
-=
boundary_size
body_size
-=
boundary_size
status
=
body
.
read
(
boundary_size
)
if
nil
==
status
raise
EOFError
,
"no content body"
...
...
@@ -541,7 +547,7 @@ def read_multipart(body, boundary, content_length, env)
loop
do
head
=
nil
content
=
if
10240
<
content_length
if
10240
<
body_size
UploadedTempfile
.
new
(
"CGI"
)
else
UploadedStringIO
.
new
...
...
@@ -563,24 +569,24 @@ def read_multipart(body, boundary, content_length, env)
buf
[
0
...
(
buf
.
size
-
(
EOL
+
boundary
+
EOL
).
size
)]
=
""
end
c
=
if
bufsize
<
content_length
c
=
if
bufsize
<
body_size
body
.
read
(
bufsize
)
else
body
.
read
(
content_length
)
body
.
read
(
body_size
)
end
if
c
.
nil?
||
c
.
empty?
raise
EOFError
,
"bad content body"
end
buf
.
concat
(
c
)
content_length
-=
c
.
size
body_size
-=
c
.
size
end
buf
=
buf
.
sub
(
/\A((?:.|\n)*?)(?:[\r\n]{1,2})?
#{
quoted_boundary
}
([\r\n]{1,2}|--)/n
)
do
content
.
print
$1
if
"--"
==
$2
content_length
=
-
1
body_size
=
-
1
end
boundary_end
=
$2
.
dup
boundary_end
=
$2
.
dup
""
end
...
...
@@ -607,7 +613,7 @@ def read_multipart(body, boundary, content_length, env)
else
params
[
name
]
=
[
content
]
end
break
if
content_length
==
-
1
break
if
body_size
==
-
1
end
raise
EOFError
,
"bad boundary end of body part"
unless
boundary_end
=~
/--/
...
...
actionpack/lib/action_controller/test_process.rb
浏览文件 @
b4330932
...
...
@@ -49,7 +49,7 @@ def body
# Either the RAW_POST_DATA environment variable or the URL-encoded request
# parameters.
def
raw_post
env
[
'RAW_POST_DATA'
]
||=
url_encoded_request_parameters
env
[
'RAW_POST_DATA'
]
||=
returning
(
url_encoded_request_parameters
)
{
|
b
|
b
.
force_encoding
(
Encoding
::
BINARY
)
if
b
.
respond_to?
(
:force_encoding
)
}
end
def
port
=
(
number
)
...
...
@@ -340,6 +340,7 @@ def initialize(path, content_type = Mime::TEXT, binary = false)
@content_type
=
content_type
@original_filename
=
path
.
sub
(
/^.*
#{
File
::
SEPARATOR
}
([^
#{
File
::
SEPARATOR
}
]+)$/
)
{
$1
}
@tempfile
=
Tempfile
.
new
(
@original_filename
)
@tempfile
.
set_encoding
(
Encoding
::
BINARY
)
if
@tempfile
.
respond_to?
(
:set_encoding
)
@tempfile
.
binmode
if
binary
FileUtils
.
copy_file
(
path
,
@tempfile
.
path
)
end
...
...
actionpack/test/controller/test_test.rb
浏览文件 @
b4330932
...
...
@@ -511,16 +511,26 @@ def test_header_properly_reset_after_get_request
FILES_DIR
=
File
.
dirname
(
__FILE__
)
+
'/../fixtures/multipart'
if
RUBY_VERSION
<
'1.9'
READ_BINARY
=
'rb'
READ_PLAIN
=
'r'
else
READ_BINARY
=
'rb:binary'
READ_PLAIN
=
'r:binary'
end
def
test_test_uploaded_file
filename
=
'mona_lisa.jpg'
path
=
"
#{
FILES_DIR
}
/
#{
filename
}
"
content_type
=
'image/png'
expected
=
File
.
read
(
path
)
expected
.
force_encoding
(
Encoding
::
BINARY
)
if
expected
.
respond_to?
(
:force_encoding
)
file
=
ActionController
::
TestUploadedFile
.
new
(
path
,
content_type
)
assert_equal
filename
,
file
.
original_filename
assert_equal
content_type
,
file
.
content_type
assert_equal
file
.
path
,
file
.
local_path
assert_equal
File
.
read
(
path
)
,
file
.
read
assert_equal
expected
,
file
.
read
end
def
test_test_uploaded_file_with_binary
...
...
@@ -529,10 +539,10 @@ def test_test_uploaded_file_with_binary
content_type
=
'image/png'
binary_uploaded_file
=
ActionController
::
TestUploadedFile
.
new
(
path
,
content_type
,
:binary
)
assert_equal
File
.
open
(
path
,
'rb'
).
read
,
binary_uploaded_file
.
read
assert_equal
File
.
open
(
path
,
READ_BINARY
).
read
,
binary_uploaded_file
.
read
plain_uploaded_file
=
ActionController
::
TestUploadedFile
.
new
(
path
,
content_type
)
assert_equal
File
.
open
(
path
,
'r'
).
read
,
plain_uploaded_file
.
read
assert_equal
File
.
open
(
path
,
READ_PLAIN
).
read
,
plain_uploaded_file
.
read
end
def
test_fixture_file_upload_with_binary
...
...
@@ -541,10 +551,10 @@ def test_fixture_file_upload_with_binary
content_type
=
'image/jpg'
binary_file_upload
=
fixture_file_upload
(
path
,
content_type
,
:binary
)
assert_equal
File
.
open
(
path
,
'rb'
).
read
,
binary_file_upload
.
read
assert_equal
File
.
open
(
path
,
READ_BINARY
).
read
,
binary_file_upload
.
read
plain_file_upload
=
fixture_file_upload
(
path
,
content_type
)
assert_equal
File
.
open
(
path
,
'r'
).
read
,
plain_file_upload
.
read
assert_equal
File
.
open
(
path
,
READ_PLAIN
).
read
,
plain_file_upload
.
read
end
def
test_fixture_file_upload
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录