Forum: Ruby on Rails URI.encode does not encode &=?

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Reynard (Guest)
on 2007-05-01 02:18
(Received via mailing list)
I'm wondering why URI.encode does not encode &=?
=> '&=?'

Is there alternative that works better? or should I write my own?

Ben M. (Guest)
on 2007-05-01 06:08
(Received via mailing list)
There's an optional second arg to specify chars to replace:

Reynard (Guest)
on 2007-05-01 07:17
(Received via mailing list)
What's the second argument supposed to be though?
should I create a regexp from scratch or use a pre-defined one? the
documentation is not very clear.
>From googling I found that some people say URI.encode is buggy and
suggested to use CGI.escape?
seems to work for me.

- reynard
Ben M. (Guest)
on 2007-05-01 08:13
(Received via mailing list)
After I sent that I got curious... I found that the second arg is just a
regex with the chars to escape... so /[&=?]/ would escape the chars
you're worried about.

I also found however, that it *only* escapes the chars in the regex if
you provide one... so you'll have to make sure to escape the stuff that
would have been escaped.

I also figured out that the REGEXP::UNSAFE constant they mention is
actually URI::REGEXP::UNSAFE. If you require 'uri' in irb and then type
that, it'll dump the chars that are in the default regex:


And, one more thing: the file that this is defined in should be at
RUBY_ROOT/uri/common.rb... and there are a lot of regexes defined in

This topic is locked and can not be replied to.