Alternate URI escaping mechanisms?

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

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…

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 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.

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