problem with CGI, multipart forms, images and MSIE Mac OS X

F

Francis Hwang

I suppose it's possible that I'm the only Ruby programmer ever to run
into this problem, but I'm having an obscure problem with the CGI
library. Maybe it's a bug or maybe I'm just missing something.

I'm using a multipart form with images for buttons and trying to
detect which image was used to submit. With a form like this:

<form action="/test/upload.rb" method="post"
enctype="multipart/form-data">
<input name="text" />
<br />Small: <input type="file" name="small" />
<br /><input type="image" src="/baseims/submit_button.gif"
name="button" />
</form>

I should get values for either "button" or "button.x" and "button.y",
or both. Depending on the browser. Here's what my /test/upload.rb
looks like:

puts "Content-type: text/html\n\n"
cgi = CGI.new
puts "<br />text: #{ cgi['text'].readlines.join( "\n" ) }"
puts "<br />button.x: #{ cgi['button.x'].readlines.join( "\n" ) }"
puts "<br />button.y: #{ cgi['button.y'].readlines.join( "\n" ) }"
puts "<br />button: #{ cgi['button'].readlines.join( "\n" ) }"

When I do this in Safari, it's fine. But when I do this in MSIE OS X,
I get nothing for any of the button values.

At first I thought this might be a MSIE problem, but I did the exact
same thing with PHP and it works fine in both Safari and MSIE. So
maybe I'm doing something really wrong, or maybe I've hit an obscure
bug? Advice would be much appreciated.

Francis
 
B

Brian Candler

At first I thought this might be a MSIE problem, but I did the exact
same thing with PHP and it works fine in both Safari and MSIE. So
maybe I'm doing something really wrong, or maybe I've hit an obscure
bug? Advice would be much appreciated.

My suggestion: write a test program which does something like

data = $stdin.read
puts "Content-type: text/html\r\n\r\n<html>#{CGI.escapeHTML(data)}</html>"

instead of using the CGI library. And do the same in PHP. Then you can tell
whether the data *is* getting posted to you by the browser (and hence a bug
in CGI which you can replicate), or is not.

Also: try printing #{ cgi.params['button'].inspect } - see if you get an
empty array, or an array containing one element (an empty string), which is
different of course.

And you could also try setting <input ..... name="button" value="foo">

Brian.
 
F

Francis Hwang

So I tried this. This is what it looks like through Safari:

------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;text&quot;


------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;small&quot;;
filename=&quot;&quot;


------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;button.x&quot;

46
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;button.y&quot;

9
------------0xKhTmLbOuNdArY--

Here's what it looks like through MSIE Mac OS X:

-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;text&quot;


-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;small&quot;;
filename=&quot;&quot;


-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;button.x&quot;

14
-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;button.y&quot;

7
-----------------------------141511461516657--

So, the data is being posted through both browser, but I can't seem to
retrieve it through the standard CGI library. The main difference is
that the boundary lines are different. Not sure if that would have any
impact.

Does this look like a bug?

Francis





Brian Candler said:
At first I thought this might be a MSIE problem, but I did the exact
same thing with PHP and it works fine in both Safari and MSIE. So
maybe I'm doing something really wrong, or maybe I've hit an obscure
bug? Advice would be much appreciated.

My suggestion: write a test program which does something like

data = $stdin.read
puts "Content-type: text/html\r\n\r\n<html>#{CGI.escapeHTML(data)}</html>"

instead of using the CGI library. And do the same in PHP. Then you can tell
whether the data *is* getting posted to you by the browser (and hence a bug
in CGI which you can replicate), or is not.

Also: try printing #{ cgi.params['button'].inspect } - see if you get an
empty array, or an array containing one element (an empty string), which is
different of course.

And you could also try setting <input ..... name="button" value="foo">

Brian.
 
P

Patrick May

Hello,

So I tried this. This is what it looks like through Safari:

------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;text&quot;


------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;small&quot;;
filename=&quot;&quot;


------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;button.x&quot;

46
------------0xKhTmLbOuNdArY
Content-Disposition: form-data; name=&quot;button.y&quot;

9
------------0xKhTmLbOuNdArY--

Here's what it looks like through MSIE Mac OS X:

-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;text&quot;


-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;small&quot;;
filename=&quot;&quot;


-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;button.x&quot;

14
-----------------------------141511461516657
Content-Disposition: form-data; name=&quot;button.y&quot;

7
-----------------------------141511461516657--

So, the data is being posted through both browser, but I can't seem to
retrieve it through the standard CGI library. The main difference is
that the boundary lines are different. Not sure if that would have any
impact.

Does this look like a bug?

The boundry doesn't matter, it just has to be unique. It may be a bug.
Narf inherits this code, I'll test it tomorrow.

~ pat
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,162
Latest member
GertrudeMa
Top