Alternate URI escaping mechanisms?

D

Davis Frank

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
 
A

Alex Young

Davis said:
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...
 
C

Carlos

Davis said:
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.
--
 
C

Carlos

Carlos said:
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.

--
 
D

Davis Frank

Carlos said:
Carlos said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top