From 76a348305d7b360f1d04172182946be4b12fbcf7 Mon Sep 17 00:00:00 2001 From: Jeremy Evans Date: Thu, 10 Oct 2019 15:32:31 -0700 Subject: [PATCH] Make RFC 3986 parser the default URI parser This is not API compatible with the previous default URI parser based on RFC 2396, so there would be some breakage. --- lib/uri/common.rb | 15 ++++++++------- lib/uri/generic.rb | 4 ++-- test/uri/test_parser.rb | 4 ++-- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/uri/common.rb b/lib/uri/common.rb index b886923c9e..641e87f253 100644 --- a/lib/uri/common.rb +++ b/lib/uri/common.rb @@ -15,17 +15,18 @@ module URI REGEXP = RFC2396_REGEXP - Parser = RFC2396_Parser - RFC3986_PARSER = RFC3986_Parser.new + Parser = RFC3986_Parser + RFC3986_PARSER = Parser.new + DEFAULT_PARSER = RFC3986_PARSER # URI::Parser.new - DEFAULT_PARSER = Parser.new - DEFAULT_PARSER.pattern.each_pair do |sym, str| + RFC2396_PARSER = RFC2396_Parser.new + RFC2396_PARSER.pattern.each_pair do |sym, str| unless REGEXP::PATTERN.const_defined?(sym) REGEXP::PATTERN.const_set(sym, str) end end - DEFAULT_PARSER.regexp.each_pair do |sym, str| + RFC2396_PARSER.regexp.each_pair do |sym, str| const_set(sym, str) end @@ -297,7 +298,7 @@ def self.join(*str) # def self.extract(str, schemes = nil, &block) warn "URI.extract is obsolete", uplevel: 1 if $VERBOSE - DEFAULT_PARSER.extract(str, schemes, &block) + RFC2396_PARSER.extract(str, schemes, &block) end # @@ -334,7 +335,7 @@ def self.extract(str, schemes = nil, &block) # def self.regexp(schemes = nil) warn "URI.regexp is obsolete", uplevel: 1 if $VERBOSE - DEFAULT_PARSER.make_regexp(schemes) + RFC2396_PARSER.make_regexp(schemes) end TBLENCWWWCOMP_ = {} # :nodoc: diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index c672d15eb2..4f1d9a813e 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -83,7 +83,7 @@ def self.build2(args) if args.kind_of?(Array) return self.build(args.collect{|x| if x.is_a?(String) - DEFAULT_PARSER.escape(x) + RFC2396_PARSER.escape(x) else x end @@ -92,7 +92,7 @@ def self.build2(args) tmp = {} args.each do |key, value| tmp[key] = if value - DEFAULT_PARSER.escape(value) + RFC2396_PARSER.escape(value) else value end diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb index b13a26ca84..000e2186d3 100644 --- a/test/uri/test_parser.rb +++ b/test/uri/test_parser.rb @@ -31,7 +31,7 @@ def test_compare def test_parse escaped = URI::REGEXP::PATTERN::ESCAPED hex = URI::REGEXP::PATTERN::HEX - p1 = URI::Parser.new(:ESCAPED => "(?:#{escaped}|%u[#{hex}]{4})") + p1 = URI::RFC2396_Parser.new(:ESCAPED => "(?:#{escaped}|%u[#{hex}]{4})") u1 = p1.parse('http://a/b/%uABCD') assert_equal(['http', nil, 'a', URI::HTTP.default_port, '/b/%uABCD', nil, nil], uri_to_ary(u1)) @@ -52,7 +52,7 @@ def test_raise_bad_uri_for_integer end def test_unescape - p1 = URI::Parser.new + p1 = URI::RFC2396_Parser.new assert_equal("\xe3\x83\x90", p1.unescape("\xe3\x83\x90")) assert_equal("\xe3\x83\x90", p1.unescape('%e3%83%90')) assert_equal("\u3042", p1.unescape('%e3%81%82'.force_encoding(Encoding::US_ASCII))) -- 2.23.0