Skip to content

Commit

Permalink
[ruby/uri] Fix host part in relative referece #83
Browse files Browse the repository at this point in the history
In relative referece, host part can be ommitted but can not be empty.

ruby/uri@2980f0ba02
  • Loading branch information
nobu authored and matzbot committed Jun 25, 2023
1 parent 15ec072 commit c21436c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/uri/rfc3986_parser.rb
Expand Up @@ -26,11 +26,6 @@ class RFC3986_Parser # :nodoc:
]x

USERINFO = /(?:%\h\h|[!$&-.0-9:;=A-Z_a-z~])*+/
AUTHORITY = %r[
(?:(?<userinfo>#{USERINFO.source})@)?
(?<host>#{HOST.source.delete(" \n")})
(?::(?<port>\d*+))?
]x

SCHEME = %r[[A-Za-z][+\-.0-9A-Za-z]*+].source
SEG = %r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/])].source
Expand All @@ -42,7 +37,11 @@ class RFC3986_Parser # :nodoc:
(?<URI>
(?<scheme>#{SCHEME}):
(?<hier-part>//
(?<authority>#{AUTHORITY})
(?<authority>
(?:(?<userinfo>#{USERINFO.source})@)?
(?<host>#{HOST.source.delete(" \n")})
(?::(?<port>\d*+))?
)
(?<path-abempty>(?:/\g<seg>*+)?)
| (?<path-absolute>/((?!/)\g<seg>++)?)
| (?<path-rootless>(?!/)\g<seg>++)
Expand All @@ -56,7 +55,11 @@ class RFC3986_Parser # :nodoc:
(?<seg>#{SEG}){0}
(?<relative-ref>
(?<relative-part>//
(?<authority>#{AUTHORITY})
(?<authority>
(?:(?<userinfo>#{USERINFO.source})@)?
(?<host>#{HOST.source.delete(" \n")}(?<!/))?
(?::(?<port>\d*+))?
)
(?<path-abempty>(?:/\g<seg>*+)?)
| (?<path-absolute>/\g<seg>*+)
| (?<path-noscheme>#{SEG_NC}++(?:/\g<seg>*+)?)
Expand Down
4 changes: 4 additions & 0 deletions test/uri/test_generic.rb
Expand Up @@ -977,6 +977,10 @@ def test_use_proxy_p
end
end

def test_split
assert_equal [nil, nil, nil, nil, nil, "", nil, nil, nil], URI.split("//")
end

class CaseInsensitiveEnv
def initialize(h={})
@h = {}
Expand Down

0 comments on commit c21436c

Please sign in to comment.