From a9ddb51210be5e7ff37e64dd42736c0ab0eec0a3 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 13 Jun 2023 13:54:44 +0900 Subject: [PATCH] Fix RFC3986 regexps --- lib/uri/rfc3986_parser.rb | 8 ++++---- test/uri/test_parser.rb | 5 +++++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb index 8cc51f1..33abb9e 100644 --- a/lib/uri/rfc3986_parser.rb +++ b/lib/uri/rfc3986_parser.rb @@ -43,8 +43,8 @@ class RFC3986_Parser # :nodoc: (?// (?#{AUTHORITY}) (?(?:/\g*+)?) - | (?/\g*+) - | (?(?!=/)\g++) + | (?/((?!/)\g++)?) + | (?(?!/)\g++) | (?) ) (?:\?(?[^\#]*+))? @@ -58,7 +58,7 @@ class RFC3986_Parser # :nodoc: (?#{AUTHORITY}) (?(?:/\g*+)?) | (?/\g*+) - | (?(?!=[:/])\g++) + | (?(?![:/])\g++(?:\/\g)*+) | (?) ) (?:\?(?[^#]*+))? @@ -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], diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb index 72fb590..7391fbf 100644 --- a/test/uri/test_parser.rb +++ b/test/uri/test_parser.rb @@ -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