summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2023-06-25 23:58:12 +0900
committergit <[email protected]>2023-06-25 15:24:05 +0000
commitc21436cb353f8194db647bde2a5ef434eb3dcb2a (patch)
tree69bdd4a63448f2d4ac08136dd3eb098a773ddb49
parent15ec072a4266cba7b3548548ef48d85d296ae9e2 (diff)
[ruby/uri] Fix host part in relative referece #83
In relative referece, host part can be ommitted but can not be empty. https://github.com/ruby/uri/commit/2980f0ba02
-rw-r--r--lib/uri/rfc3986_parser.rb17
-rw-r--r--test/uri/test_generic.rb4
2 files changed, 14 insertions, 7 deletions
diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb
index 59e2be2805..ffdcfa9227 100644
--- a/lib/uri/rfc3986_parser.rb
+++ b/lib/uri/rfc3986_parser.rb
@@ -26,11 +26,6 @@ module URI
]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
@@ -42,7 +37,11 @@ module URI
(?<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>++)
@@ -56,7 +55,11 @@ module URI
(?<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>*+)?)
diff --git a/test/uri/test_generic.rb b/test/uri/test_generic.rb
index 3897c3d6ee..e6619373c6 100644
--- a/test/uri/test_generic.rb
+++ b/test/uri/test_generic.rb
@@ -977,6 +977,10 @@ class URI::TestGeneric < Test::Unit::TestCase
end
end
+ def test_split
+ assert_equal [nil, nil, nil, nil, nil, "", nil, nil, nil], URI.split("//")
+ end
+
class CaseInsensitiveEnv
def initialize(h={})
@h = {}