Issue #4167 has been updated by George M. Harkin.
Workaround is to use
exp = URI.encode(x, Regexp.new("[^#{URI::PATTERN::UNRESERVED}#{URI::PATTERN::RESERVED}#]", false, 'N'))
where x is the URL with a # symbol for an anchor tag
----------------------------------------
http://redmine.ruby-lang.org/issues/show/4167
----------------------------------------
http://redmine.ruby-lang.org