Skip to content

Commit

Permalink
Fix RFC3986 regexps
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Jun 13, 2023
1 parent c1d1757 commit a9ddb51
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/uri/rfc3986_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class RFC3986_Parser # :nodoc:
(?<hier-part>//
(?<authority>#{AUTHORITY})
(?<path-abempty>(?:/\g<seg>*+)?)
| (?<path-absolute>/\g<seg>*+)
| (?<path-rootless>(?!=/)\g<seg>++)
| (?<path-absolute>/((?!/)\g<seg>++)?)
| (?<path-rootless>(?!/)\g<seg>++)
| (?<path-empty>)
)
(?:\?(?<query>[^\#]*+))?
Expand All @@ -58,7 +58,7 @@ class RFC3986_Parser # :nodoc:
(?<authority>#{AUTHORITY})
(?<path-abempty>(?:/\g<seg>*+)?)
| (?<path-absolute>/\g<seg>*+)
| (?<path-noscheme>(?!=[:/])\g<seg>++)
| (?<path-noscheme>(?![:/])\g<seg>++(?:\/\g<seg>)*+)
| (?<path-empty>)
)
(?:\?(?<query>[^#]*+))?
Expand Down Expand Up @@ -156,7 +156,7 @@ def default_regexp # :nodoc:
USERINFO: %r[\A#{USERINFO}\z]o,
HOST: %r[\A#{HOST}\z]o,
ABS_PATH: %r[\A/#{SEG}*+\z]o,
REL_PATH: %r[\A(?!=/)#{SEG}++\z]o,
REL_PATH: %r[\A(?!/)#{SEG}++\z]o,
QUERY: %r[\A(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+\z],
FRAGMENT: %r[\A#{FRAGMENT}\z]o,
OPAQUE: %r[\A(?:[^/].*)?\z],
Expand Down
5 changes: 5 additions & 0 deletions test/uri/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,10 @@ def test_split
assert_equal(["http", nil, "[0::0]", nil, nil, "", nil, nil, nil], URI.split("http://[0::0]"))
assert_equal([nil, nil, "example.com", nil, nil, "", nil, nil, nil], URI.split("//example.com"))
assert_equal([nil, nil, "[0::0]", nil, nil, "", nil, nil, nil], URI.split("//[0::0]"))

assert_equal(["a", nil, nil, nil, nil, "", nil, nil, nil], URI.split("a:"))
assert_raise(URI::InvalidURIError) do
URI.parse("::")
end
end
end

0 comments on commit a9ddb51

Please sign in to comment.