-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix parsing of scheme that are invalid Ruby constant names #27
Conversation
lib/uri/common.rb
Outdated
@@ -91,7 +91,7 @@ def self.for(scheme, *arguments, default: Generic) | |||
const_name = scheme.to_s.upcase | |||
|
|||
uri_class = INITIAL_SCHEMES[const_name] | |||
if !uri_class && !const_name.empty? && Schemes.const_defined?(const_name, false) | |||
if !uri_class && !const_name.empty? && /\A[A-Z][A-Z0-9_]+\z/.match?(const_name) && Schemes.const_defined?(const_name, false) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&& !const_name.empty?
can be removed with this change.
/\A[A-Z][A-Z0-9_]+\z/.match?(const_name)
Should it be /\A[A-Z]\w*\z/.match?(const_name)
rather (allow lowercase letters from the 2nd character, single upper character allowed)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Definitely, I shouldn't have implemented this this late. Will fix.
assert_equal 'ms-search', URI.parse('ms-search://localhost').scheme | ||
assert_equal 'microsoft.windows.camera', URI.parse('microsoft.windows.camera://localhost').scheme | ||
assert_equal 'coaps+ws', URI.parse('coaps+ws:localhost').scheme | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be interesting to add a test for register_scheme
with a -
, .
or +
.
Probably ends up in an exception, but better than e.g. allowing to register but then the class is not used when parsing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I wasn't sure if the intent was to have register_scheme
be a public API or not. My priority was to fix the parsing of arbitrary schemes.
If register is public API, then I'd rather leave it to you to fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I"d consider it public API because it is documented in
Line 33 in 86de79c
# register_scheme 'RSYNC', RSYNC |
Some symbols such as `-`, `+` or `.` are valid inside URI schemes. See: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
9acb667
to
59925ca
Compare
@eregon should be good to go now. I'd rather handle testing |
Thanks for the fix! |
BTW, it's interesting that |
Thanks for the merge.
I had the exact same thought. Not sure if worth changing upstream. On another note, may I request for this changed to be pulled in ruby soonish? It's much harder to spot new breaking changes when we have existing failing tests. |
* ruby/uri@bc47bf7 * To include the fix from ruby/uri#27
Done: ruby/ruby@59a65f2 |
This fixes a regression from #26
https://buildkite.com/rails/rails/builds/79689#6a1b7cfc-fa17-4752-bc27-62158a228e79/1018-1029
Some symbols such as
-
,+
or.
are valid inside URI schemes.See: https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml
@eregon @hsbt