URI encode and param lost

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=éé%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,

···

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

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'
=> #<URI::HTTP:0x956a280 URL:http://foo.com/posts&gt;
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
=> #<URI::HTTP:0x956a280
URL:http://foo.com/posts?id=30&limit=éé#time=1305298413&gt;
irb(main):048:0> puts u
http://foo.com/posts?id=30&limit=éé#time=1305298413
=> nil

Kind regards

robert

···

On Sun, Jun 10, 2012 at 12:24 AM, rubix Rubix <lists@ruby-forum.com> 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=éé%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,

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/