Skip to content

Instantly share code, notes, and snippets.

@nahi
Created March 8, 2009 12:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nahi/75754 to your computer and use it in GitHub Desktop.
Save nahi/75754 to your computer and use it in GitHub Desktop.
for actionpack-2.2.2
--- lib/action_controller/request.rb.org 2009-02-27 22:50:53.000000000 +0900
+++ lib/action_controller/request.rb 2009-03-08 20:54:16.000000000 +0900
@@ -647,12 +647,22 @@ EOM
body.string.force_encoding(Encoding::BINARY) if body.string.respond_to?(:force_encoding)
end
- boundary_size = boundary.size + EOL.size
- body_size -= boundary_size
- status = body.read(boundary_size)
- if nil == status
- raise EOFError, "no content body"
- elsif boundary + EOL != status
- raise EOFError, "bad content body"
+ status = body.read(boundary.size)
+ until /#{quoted_boundary}\z/n.match(status)
+ status += body.read(1)
+ end
+ body_size -= status.size
+ c = body.read(1)
+ if c == "\n"
+ eol = c
+ else
+ c += body.read(1)
+ if c == "\r\n"
+ eol = c
+ else
+ raise EOFError, "bad content body: #{status}#{c} as a delimiter"
+ end
end
+ body_size -= eol.size
+ delimiter = eol + boundary + eol
loop do
@@ -666,8 +676,8 @@ EOM
content.binmode if defined? content.binmode
- until head and /#{quoted_boundary}(?:#{EOL}|--)/n.match(buf)
+ until head and /#{quoted_boundary}(?:#{eol}|--)/n.match(buf)
- if (not head) and /#{EOL}#{EOL}/n.match(buf)
- buf = buf.sub(/\A((?:.|\n)*?#{EOL})#{EOL}/n) do
+ if (not head) and /#{eol}#{eol}/n.match(buf)
+ buf = buf.sub(/\A((?:.|\n)*?#{eol})#{eol}/n) do
head = $1.dup
""
@@ -676,7 +686,7 @@ EOM
end
- if head and ( (EOL + boundary + EOL).size < buf.size )
- content.print buf[0 ... (buf.size - (EOL + boundary + EOL).size)]
- buf[0 ... (buf.size - (EOL + boundary + EOL).size)] = ""
+ if head and ( delimiter.size < buf.size )
+ content.print buf[0 ... (buf.size - delimiter.size)]
+ buf[0 ... (buf.size - delimiter.size)] = ""
end
@@ -704,5 +714,5 @@ EOM
content.rewind
- head =~ /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;]*))/ni
+ head =~ /Content-Disposition:.*\bfilename=(?:"((?:\\.|[^\"])*)"|([^;]*))/ni
if filename = $1 || $2
if /Mac/ni.match(env['HTTP_USER_AGENT']) and
@@ -717,5 +727,5 @@ EOM
content.content_type = $1.dup if $1
- head =~ /Content-Disposition:.* name="?([^\";]*)"?/ni
+ head =~ /Content-Disposition:.*\bname="?([^\";]*)"?/ni
name = $1.dup if $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment