Skip to content

Instantly share code, notes, and snippets.

@nahi
Created March 8, 2009 12:03
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/75749 to your computer and use it in GitHub Desktop.
Save nahi/75749 to your computer and use it in GitHub Desktop.
for ruby_1_8 r22821
Index: cgi.rb
===================================================================
--- cgi.rb (リビジョン 22821)
+++ cgi.rb (作業コピー)
@@ -980,14 +980,24 @@
# start multipart/form-data
stdinput.binmode if defined? stdinput.binmode
- boundary_size = boundary.size + EOL.size
- content_length -= boundary_size
- status = stdinput.read(boundary_size)
- if nil == status
- raise EOFError, "no content body"
- elsif boundary + EOL != status
- raise EOFError, "bad content body"
+ status = stdinput.read(boundary.size)
+ until /#{quoted_boundary}\z/n.match(status)
+ status += stdinput.read(1)
end
+ content_length -= status.size
+ c = stdinput.read(1)
+ if c == "\n"
+ eol = c
+ else
+ c += stdinput.read(1)
+ if c == "\r\n"
+ eol = c
+ else
+ raise EOFError, "bad content body: #{status}#{c} as a delimiter"
+ end
+ end
+ content_length -= eol.size
+ delimiter = eol + boundary + eol
loop do
head = nil
@@ -1005,19 +1015,19 @@
end
body.binmode if defined? body.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
""
end
next
end
- if head and ( (EOL + boundary + EOL).size < buf.size )
- body.print buf[0 ... (buf.size - (EOL + boundary + EOL).size)]
- buf[0 ... (buf.size - (EOL + boundary + EOL).size)] = ""
+ if head and ( delimiter.size < buf.size )
+ body.print buf[0 ... (buf.size - delimiter.size)]
+ buf[0 ... (buf.size - delimiter.size)] = ""
end
c = if bufsize < content_length
@@ -1043,7 +1053,7 @@
body.rewind
- /Content-Disposition:.* filename=(?:"((?:\\.|[^\"])*)"|([^;\s]*))/ni.match(head)
+ /Content-Disposition:.*\bfilename=(?:"((?:\\.|[^\"])*)"|([^;\s]*))/ni.match(head)
filename = ($1 or $2 or "")
if /Mac/ni.match(env_table['HTTP_USER_AGENT']) and
/Mozilla/ni.match(env_table['HTTP_USER_AGENT']) and
@@ -1060,7 +1070,7 @@
define_method(:content_type) {content_type.dup.taint}
end
- /Content-Disposition:.* name="?([^\";\s]*)"?/ni.match(head)
+ /Content-Disposition:.*\bname="?([^\";\s]*)"?/ni.match(head)
name = $1.dup
if params.has_key?(name)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment