[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Alternate URI escaping mechanisms?

Davis Frank

1/16/2007 11:24:00 PM

URI#escape escapes to UTF-8. I need to escape to Latin-1 for Amazon's
REST API. Is there another library I can use? There doesn't seem to be
a way to change what URI#escape uses (at least, not from the skeleton
std API docs).

I'm getting very little to go on via searching.

--dwf

--
Posted via http://www.ruby-....

4 Answers

Alex Young

1/16/2007 11:30:00 PM

0

Davis Frank wrote:
> URI#escape escapes to UTF-8. I need to escape to Latin-1 for Amazon's
> REST API. Is there another library I can use? There doesn't seem to be
> a way to change what URI#escape uses (at least, not from the skeleton
> std API docs).
>
> I'm getting very little to go on via searching.

Iconv may be what you're after...

--
Alex


Carlos

1/16/2007 11:43:00 PM

0

Davis Frank wrote:
> URI#escape escapes to UTF-8. I need to escape to Latin-1 for Amazon's
> REST API. Is there another library I can use? There doesn't seem to be
> a way to change what URI#escape uses (at least, not from the skeleton
> std API docs).
>
> I'm getting very little to go on via searching.

URI#escape escapes to UTF-8 because your string is UTF-8-encoded. Use
iconv, as Alex suggested, to re-encode it to Latin-1, or do it with
unpack and pack
str.unpack("U*").pack("C*")

and then apply URI#escape.

Of course, both methods will fail if any character in your string is
outside the Latin-1 range.

Good luck.
--



Carlos

1/16/2007 11:51:00 PM

0

Carlos wrote:
>> URI#escape escapes to UTF-8. I need to escape to Latin-1 for Amazon's
[...]
> URI#escape escapes to UTF-8 because your string is UTF-8-encoded. Use
[...]
> and then apply URI#escape.

Correction: it's not URI#escape but URI.escape.

--



Davis Frank

1/17/2007 1:05:00 AM

0

Carlos wrote:
> Carlos wrote:
>>> URI#escape escapes to UTF-8. I need to escape to Latin-1 for Amazon's
> [...]
>> URI#escape escapes to UTF-8 because your string is UTF-8-encoded. Use
> [...]
>> and then apply URI#escape.

I found Iconv, but my head was bent the wrong way. I was escaping, then
converting instead of converting, then escaping.

The magic is here:
URI.escape(Iconv.new('latin1', 'utf-8').iconv(value))

Now everything is happy. Thanks for the quick response.

--dwf


--
Posted via http://www.ruby-....