1

Using Rails 3.2.13 with Ruby 1.8.7

I have this utf-8 url: "http://google.com/?禾楼囖谈河任"

when I use

redirect_to "http://google.com/?禾楼囖谈河任"

It gets - Redirected to http://google.com/???????
However when I print out the bytes using unpack('U*'), it outputs the correct unicode sequence as below:

[104, 116, 116, 112, 58, 47, 47, 103, 111, 111, 103, 108, 101, 46, 99, 111, 109, 47, 63, 31166, 27004, 22230, 35848, 27827, 20219]

I want it to redirect to the utf-8 url.
Can anyone help?
Thanks

pchu
  • 171
  • 1
  • 2
  • 10
  • 1
    Read http://yehudakatz.com/2010/05/05/ruby-1-9-encodings-a-primer-and-the-solution-for-rails/ – photoionized Apr 10 '14 at 21:23
  • I also posted [this answer](http://stackoverflow.com/questions/22957144/sanitizing-unicode-strings-for-url-slugs-ruby-rails/22958682#22958682) the other day that should be somewhat relevant. – Mike H-R Apr 10 '14 at 21:55

1 Answers1

0

Just try:

url = "http://google.com/?禾楼囖谈河任"

final_URL = URI.escape(url, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))

redirect_to final_URL

Hope it helps :)

Rajesh Omanakuttan
  • 6,788
  • 7
  • 47
  • 85