Forum: Ruby CGI.escape accepts only ISO-8859-1 input?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Deb260c4c4835353b2e25da2bf0a5727?d=identicon&s=25 Martin (Guest)
on 2007-06-27 17:21
(Received via mailing list)

I'm not able to convert a string to ISO-8859-1.
Could anyone please try to help me out here?


message = ARGV[0]

# This doesn't seem to work, what am I doing wrong?'ISO-8859-1', 'UTF-8').iconv(message)

encoded_message = CGI.escape(message) rescue nil
puts "Argument #{message} translates to #{encoded_message}\n"

# Script stop.

If I set my terminal to UTF-8, I got this output:
Argument input_as-UTF-8_ÆØÅ translates to input_as-UTF-8_

Terminal set to ISO-8859-1:
Argument input_as-ISO-8859-1_ÆØÅ translates to input_as-ISO-8859-1_

Any help would be highly appreciated!
Deb260c4c4835353b2e25da2bf0a5727?d=identicon&s=25 Martin (Guest)
on 2007-06-27 17:26
(Received via mailing list)
Forgot to paste what I have included in the script:

require 'iconv'
require 'cgi'

813f535246722b7bf02aacc9ce818de8?d=identicon&s=25 Bob Showalter (Guest)
on 2007-06-27 17:51
(Received via mailing list)
On 6/27/07, Martin <> wrote:
>'ISO-8859-1', 'UTF-8').iconv(message)
You're discarding the return value. Perhaps you mean:

   message ='ISO-8859-1', 'UTF-8').iconv(message)
This topic is locked and can not be replied to.