From: Robert Klemme Date: 2012-06-10T19:42:30+09:00 Subject: Re: URI encode and param lost On Sun, Jun 10, 2012 at 12:24 AM, rubix Rubix wrote: > Hi, > I have an url: http://foo.com/posts?id=30&limit=יי#time=1305298413 > I am using uri class to parse it: URI::split(url) > the problem is I need to encode it: URI.encode(url) first, which it > gives > http://foo.com/posts?id=30&limit=%C3%A9%C3%A9%23time=1305298413 > but with encoding it the fragment is lost and I can't > perform the split function > > Can anyone help me to solve this problem > regards, The issue is that your original URI is not a valid URI since it contains characters which are not allowed in the URI. Basically you need to encode parameters _before_ you put them in the URI to make it a valid URI and have URI.split work successfully: irb(main):044:0> u = URI.parse 'http://foo.com/posts' => # irb(main):045:0> u.query = {id:30,limit:'יי'}.map{|k,v|"#{k}=#{URI.encode(v.to_s)}"}.join '&' => "id=30&limit=%C3%A9%C3%A9" irb(main):046:0> u.fragment='time=1305298413' => "time=1305298413" irb(main):047:0> u => # irb(main):048:0> puts u http://foo.com/posts?id=30&limit=%C3%A9%C3%A9#time=1305298413 => nil Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/