Le 20 ao 2008 22:25, Nick Brown a rit :

> F. Senault wrote:
>> Please provide some code to demonstrate this.

Don't ask me why (yet) but...

> a = cgi['a']
a = cgi['a'].dup

and...

22:47 fred@balvenie:~/> ruby test.rb
(offline mode: enter name=value pairs on standard input)
a=hi
Inserting value a=bye into the database.
What was actually inserted into the database: bye

...

It seems that CGI does horrible, horrible things to its strings :

require 'cgi'
cgi = CGI.new('html4')

a = cgi['a'] #.dup
b = cgi['a'].dup

puts "A :"
a.sub!(/hi/, 'bye')
puts a.to_s
puts a.inspect
puts a.class

puts "B :"
b.sub!(/hi/, 'bye')
puts b.to_s
puts b.inspect
puts b.class

Gives :

22:53 fred@balvenie:~> ruby test.rb
(offline mode: enter name=value pairs on standard input)
a=hi
A :
hi
"bye"
String
B :
bye
"bye"
String

Ugh !

Fred
-- 
Tried to save a place from the cuts and the scratches 
Tried to overcome the complications and the catches
Nothing ever grows and the sun doesn't shine all day   (Nine Inch Nails,
Tried to save myself but myself keeps slipping away       Into the Void)