Skip to content

Commit

Permalink
Fix host part in relative referece ruby#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.
  • Loading branch information
nobu committed Jun 25, 2023
1 parent c0aa1ec commit 6b64023
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions lib/uri/rfc3986_parser.rb
Original file line number Diff line number Diff line change
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

0 comments on commit 6b64023

Please sign in to comment.