Wierd cgi behaviour in PP Ruby 1.8.0

Well it’s the short calm period before the storm of an upcoming product
release and I 'm stealing time to code something interesting for a change.
And I’ve picked the time to switch from 1.6.8 to 1.8.0 :). Unfortunately
the calm period is much too short to be able to do it on the Linux boxes
(where code of some actual value is running :wink: ) so I’m playing about
with the PP package.
And I’ve stumbled on some wierd behaviour using CGI.
The following code is straightforward and simple:

def taken? name
b=[“one”,“two”]
return “” if (b.include?(name) )
return " not"
end

name=“one”
puts “#{name} does #{taken?(name)} exist”
name=“three”
puts “#{name} does #{taken?(name)} exist”

will give:

ruby simple.rb
one does exist
three does not exist.

Now, using a simple form and a mini http server (it’s called Xerver -
it’s a java thingy that comes in handy) that is cgi capable I duplicate
this functionality in the following:

require ‘cgi’
def taken? name
b=[“one”,“two”]
return “” if (b.include?(name) )
return " not"
end
cgi = CGI.new(“html3”) # add HTML generation methods
cgi.out {
cgi.html { cgi.head { cgi.title{“Availability”} }+
cgi.body { name=cgi.params[“name”]
“#{name} does #{taken?(name)} exist”}
}
}

which outputs:

one does not exist

and

three does not exist

Does anybody have any idea why this would happen?
I’ll test it on an Apache installation I’ve got, but I can’t see why it
would be any different.
V.-

···

http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.

Well it’s the short calm period before the storm of an upcoming
product release and I 'm stealing time to code something interesting
for a change. And I’ve picked the time to switch from 1.6.8 to 1.8.0
:). Unfortunately the calm period is much too short to be able to do
it on the Linux boxes (where code of some actual value is running :wink: )
so I’m playing about with the PP package. And I’ve stumbled on some
wierd behaviour using CGI. The following code is straightforward and
simple:

def taken? name
b=[“one”,“two”]
return “” if (b.include?(name) )
return " not"
end

name=“one”
puts “#{name} does #{taken?(name)} exist”
name=“three”
puts “#{name} does #{taken?(name)} exist”

will give:

ruby simple.rb
one does exist
three does not exist.

Now, using a simple form and a mini http server (it’s called Xerver -
it’s a java thingy that comes in handy) that is cgi capable I
duplicate this functionality in the following:

require ‘cgi’
def taken? name
b=[“one”,“two”]
return “” if (b.include?(name) )
return " not"
end
cgi = CGI.new(“html3”) # add HTML generation methods
cgi.out {
cgi.html { cgi.head { cgi.title{“Availability”} }+
cgi.body { name=cgi.params[“name”]
“#{name} does #{taken?(name)} exist”}
}
}

which outputs:

one does not exist

and

three does not exist

Does anybody have any idea why this would happen?
I’ll test it on an Apache installation I’ve got, but I can’t see why
it would be any different. V.-

I believe cgi.params will return an array of values. So if the url
was url?name=one then cgi.params[“name”] would be [“one”] and that
would show up as not existing but a single valued array would just
print the value using “#{}”.

Walt

···

Walter Szewelanczyk
IS Director
M.W. Sewall & CO. email : walter@mwsewall.com
259 Front St. Phone : (207) 442-7994 x 128
Bath, ME 04530 Fax : (207) 443-6284


walter@mwsewall.com wrote:

Well it’s the short calm period before the storm of an upcoming
too much blabla

Does anybody have any idea why this would happen?
I’ll test it on an Apache installation I’ve got, but I can’t see why
it would be any different. V.-

I believe cgi.params will return an array of values. So if the url
was url?name=one then cgi.params[“name”] would be [“one”] and that
would show up as not existing but a single valued array would just
print the value using “#{}”.

And yes you are right. According to the Pickaxe book, CGI#params returns
a hash - I just didn’t expect the value of the hash to be an array -
silly me.
Thanx,
V.-

···

http://www.freemail.gr - äùñåÜí õðçñåóßá çëåêôñïíéêïý ôá÷õäñïìåßïõ.
http://www.freemail.gr - free email service for the Greek-speaking.