[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

CGI.escape accepts only ISO-8859-1 input?

Martin

6/27/2007 3:17:00 PM

Hi,

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

#!/usr/bin/ruby

message = ARGV[0]

# This doesn't seem to work, what am I doing wrong?
Iconv.new('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_
%C3%86%C3%98%C3%85

Terminal set to ISO-8859-1:
Argument input_as-ISO-8859-1_ÆØÅ translates to input_as-ISO-8859-1_
%C6%D8%C5


Any help would be highly appreciated!

2 Answers

Martin

6/27/2007 3:22:00 PM

0

Forgot to paste what I have included in the script:

require 'iconv'
require 'cgi'

--
Martin


On Jun 27, 5:16 pm, Martin <martin.stabenfe...@gmail.com> wrote:
> Hi,
>
> I'm not able to convert a string to ISO-8859-1.
> Could anyone please try to help me out here?
>
> #!/usr/bin/ruby
>
> message = ARGV[0]
>
> # This doesn't seem to work, what am I doing wrong?
> Iconv.new('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_
> %C3%86%C3%98%C3%85
>
> Terminal set to ISO-8859-1:
> Argument input_as-ISO-8859-1_ÆØÅ translates to input_as-ISO-8859-1_
> %C6%D8%C5
>
> Any help would be highly appreciated!


Bob Showalter

6/27/2007 3:50:00 PM

0

On 6/27/07, Martin <martin.stabenfeldt@gmail.com> wrote:
> Hi,
>
> I'm not able to convert a string to ISO-8859-1.
> Could anyone please try to help me out here?
>
> #!/usr/bin/ruby
>
> message = ARGV[0]
>
> # This doesn't seem to work, what am I doing wrong?
> Iconv.new('ISO-8859-1', 'UTF-8').iconv(message)

You're discarding the return value. Perhaps you mean:

message = Iconv.new('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_
> %C3%86%C3%98%C3%85
>
> Terminal set to ISO-8859-1:
> Argument input_as-ISO-8859-1_ÆØÅ translates to input_as-ISO-8859-1_
> %C6%D8%C5
>
>
> Any help would be highly appreciated!
>
>
>