diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb index 41fbea4b03bd79..092a1ac89d4dcb 100644 --- a/lib/uri/rfc3986_parser.rb +++ b/lib/uri/rfc3986_parser.rb @@ -164,7 +164,7 @@ def default_regexp # :nodoc: QUERY: %r[\A(?:%\h\h|[!$&-.0-9:;=@A-Z_a-z~/?])*+\z], FRAGMENT: %r[\A#{FRAGMENT}\z]o, OPAQUE: %r[\A(?:[^/].*)?\z], - PORT: /\A[\x09\x0a\x0c\x0d ]*\d*[\x09\x0a\x0c\x0d ]*\z/, + PORT: /\A[\x09\x0a\x0c\x0d ]*+\d*[\x09\x0a\x0c\x0d ]*\z/, } end diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb index 55abe2c583a83f..75c02fe65b3d02 100644 --- a/test/uri/test_parser.rb +++ b/test/uri/test_parser.rb @@ -99,4 +99,14 @@ def test_rfc2822_parse_relative_uri end end end + + def test_rfc3986_port_check + pre = ->(length) {"\t" * length + "a"} + uri = URI.parse("http://my.example.com") + assert_linear_performance((1..5).map {|i| 10**i}, pre: pre) do |port| + assert_raise(URI::InvalidComponentError) do + uri.port = port + end + end + end end