Incompatible changes to cgi.rb in 1.8.0

B

Brian Candler

Hmm, something has changed in CGI which has broken an application - sorry I
didn't have a chance to test/comment on this before 1.8.0 was released, but
anyway here's the information now.

@cgi['foo'][0] used to return nil if parameter 'foo' was not supplied by the
user. It now returns empty string; so does @cgi['foo']

This is a bit of a problem, since I have code which says

if @cgi['foo'][0]
.. do stuff if parameter 'foo' is supplied
end

in lots of places. But in any case, surely "parameter is missing" should be
represented by nil, since the condition "parameter is present but is an
empty string" is different?

The solution I have found is

if @cgi.params['foo'][0]
..
endif

But that seems to be rather against the spirit of the change to the cgi.rb
module, which was supposed to make accessing parameters *easier*, not more
convoluted...

Cheers,

Brian.
 
B

Brian Candler

I found another set of places where this change breaks things:

foo( @cgi['bar'][0] || 'default value' )

no longer works, because the left-hand side returns empty string. I am very
happy with the practice of "nil is false, strings (including empty) and
numbers (including zero) are true" but it doesn't work here any more :-(

Still, a global search-replace of
@cgi[
with
@cgi.params[
seems to have done the trick.

Regards,

Brian.
 

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

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top