Skip to content

Commit 2980f0b

Browse files
committed
Fix host part in relative referece #83
In relative referece, host part can be ommitted but can not be empty.
1 parent 4ed50df commit 2980f0b

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

lib/uri/rfc3986_parser.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ class RFC3986_Parser # :nodoc:
2626
]x
2727

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

3530
SCHEME = %r[[A-Za-z][+\-.0-9A-Za-z]*+].source
3631
SEG = %r[(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/])].source
@@ -42,7 +37,11 @@ class RFC3986_Parser # :nodoc:
4237
(?<URI>
4338
(?<scheme>#{SCHEME}):
4439
(?<hier-part>//
45-
(?<authority>#{AUTHORITY})
40+
(?<authority>
41+
(?:(?<userinfo>#{USERINFO.source})@)?
42+
(?<host>#{HOST.source.delete(" \n")})
43+
(?::(?<port>\d*+))?
44+
)
4645
(?<path-abempty>(?:/\g<seg>*+)?)
4746
| (?<path-absolute>/((?!/)\g<seg>++)?)
4847
| (?<path-rootless>(?!/)\g<seg>++)
@@ -56,7 +55,11 @@ class RFC3986_Parser # :nodoc:
5655
(?<seg>#{SEG}){0}
5756
(?<relative-ref>
5857
(?<relative-part>//
59-
(?<authority>#{AUTHORITY})
58+
(?<authority>
59+
(?:(?<userinfo>#{USERINFO.source})@)?
60+
(?<host>#{HOST.source.delete(" \n")}(?<!/))?
61+
(?::(?<port>\d*+))?
62+
)
6063
(?<path-abempty>(?:/\g<seg>*+)?)
6164
| (?<path-absolute>/\g<seg>*+)
6265
| (?<path-noscheme>#{SEG_NC}++(?:/\g<seg>*+)?)

test/uri/test_generic.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,10 @@ def test_use_proxy_p
977977
end
978978
end
979979

980+
def test_split
981+
assert_equal [nil, nil, nil, nil, nil, "", nil, nil, nil], URI.split("//")
982+
end
983+
980984
class CaseInsensitiveEnv
981985
def initialize(h={})
982986
@h = {}

0 commit comments

Comments
 (0)