views:

27

answers:

1

I'm trying to parse a URI with Ruby's URI library. This URI contains a #. For example, I have the URI: http://twitter.com/#!/dhh/status/26464821879

When I call URI.parse("http://twitter.com/#!/dhh/status/26464821879").path "/" is returned, when I would expect to see "/#!/dhh/status/26464821879" returned.

How can I get URI.parse to properly return the path for this URI object?

+1  A: 

this is not the path you want, it is the fragment

ruby-1.8.7-p174 > u = URI.parse("http://twitter.com/#!/dhh/status/26464821879")
 => #<URI::HTTP:0x10071add0 URL:http://twitter.com/#!/dhh/status/26464821879&gt; 
ruby-1.8.7-p174 > u.path
 => "/" 
ruby-1.8.7-p174 > u.fragment
 => "!/dhh/status/26464821879"
hellvinz
thanks for this, this helps somewhat. I guess my concern is when you call .path with the old style Twitter URL (ie. http://twitter.com/dhh/status/26464821879) without the #! it returns what I wanted. But the #! ruins this for some reason.
Paul Fedory