I'm trying to figure out what the default set of unsafe characters is for URI.escape in ruby 2.2.3. The docs say:
By default uses REGEXP::UNSAFE
But I can't find that constant anywhere in the URI module.
Additionally, this code (snippet below) has the escape / unescape methods marked as 'obsolete' since 2009. Why are they obsolete?
lib/uri/common.rb:97
def escape(*arg)
warn "#{caller(1)[0]}: warning: URI.escape is obsolete" if $VERBOSE
DEFAULT_PARSER.escape(*arg)
end
Are the docs just wrong / out of date?
I see you answered your question re: UNSAFE
. As to this question:
Additionally, this code has the escape / unescape methods marked as 'obsolete' since 2009. Why are they obsolete?
There's some background in this Dec. 2010 issue: https://bugs.ruby-lang.org/issues/4167 In that thread Yui Naruse writes:
URI lib says it refers RFC2396, so current behavior is correct in its spec.
Yes, I know current behavior is not what you expect. So we plan to change the lib to refer RFC3986.
Moreover current URI.encode is simple gsub. But I think it should split a URI to components, then escape each components, and finally join them.
So current URI.encode is considered harmful and deprecated. This will be removed or change behavior drastically.
What is the replacement at this time?
As I said above, current URI.encode is wrong on spec level. So we won't provide the exact replacement. The replacement will vary by its use case.
We thought most use case is to generate escaped URI from joined URI componets. For this, people should use URI.join or URI.encode_www_form; you should escape each components before join them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With