tags:

views:

42

answers:

1

Is there a quick way to clean up a url that is malformed with a 2nd question mark instead of ampersand? i.e.

http://google.com?x=1?y=2

thx

+2  A: 
'http://google.com?x=1?y=2'.split('?',2).map{|i| i.gsub('?', '&')}.join('?')
#=> "http://google.com?x=1&y=2"
Mladen Jablanović
Note that this will fix `http://google.com?x=1?y=2?z=3`, too -- although if the url string is correctly formed, it will break it.
Shadowfirebird
Actually, the original URL is not malformed, only unconventional. Everything after the domain is considered a query string and is purely matter of convention between the client and the server. :)
Mladen Jablanović