From 9997c1aceedfc205aa4f956b17d09b88feaf2fe2 Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 8 Aug 2024 10:44:52 +0900 Subject: [PATCH 1/2] Warn compatibility methods in RFC3986_PARSER --- lib/uri/rfc3986_parser.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/uri/rfc3986_parser.rb b/lib/uri/rfc3986_parser.rb index cac75a3..a8a8c74 100644 --- a/lib/uri/rfc3986_parser.rb +++ b/lib/uri/rfc3986_parser.rb @@ -147,16 +147,19 @@ def extract(str, schemes = nil, &block) # :nodoc: # Compatibility for RFC2396 parser def make_regexp(schemes = nil) # :nodoc: + warn "URI::RFC3986_PARSER.make_regexp is obsoleted. Use URI::RFC2396_PARSER.make_regexp explicitly.", uplevel: 1 if $VERBOSE RFC2396_PARSER.make_regexp(schemes) end # Compatibility for RFC2396 parser def escape(str, unsafe = nil) # :nodoc: + warn "URI::RFC3986_PARSER.escape is obsoleted. Use URI::RFC2396_PARSER.escape explicitly.", uplevel: 1 if $VERBOSE unsafe ? RFC2396_PARSER.escape(str, unsafe) : RFC2396_PARSER.escape(str) end # Compatibility for RFC2396 parser def unescape(str, escaped = nil) # :nodoc: + warn "URI::RFC3986_PARSER.unescape is obsoleted. Use URI::RFC2396_PARSER.unescape explicitly.", uplevel: 1 if $VERBOSE escaped ? RFC2396_PARSER.unescape(str, escaped) : RFC2396_PARSER.unescape(str) end From 898b889811e5978b967eb5c73fe3b273b736552c Mon Sep 17 00:00:00 2001 From: Hiroshi SHIBATA Date: Thu, 8 Aug 2024 11:06:03 +0900 Subject: [PATCH 2/2] Use URI::RFC2396_PARSER explicitly in URI --- lib/uri/generic.rb | 4 ++-- test/uri/test_parser.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/uri/generic.rb b/lib/uri/generic.rb index bdd3666..7b48c9b 100644 --- a/lib/uri/generic.rb +++ b/lib/uri/generic.rb @@ -82,7 +82,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) + URI::RFC2396_PARSER.escape(x) else x end @@ -91,7 +91,7 @@ def self.build2(args) tmp = {} args.each do |key, value| tmp[key] = if value - DEFAULT_PARSER.escape(value) + URI::RFC2396_PARSER.escape(value) else value end diff --git a/test/uri/test_parser.rb b/test/uri/test_parser.rb index 9105d47..f455a5c 100644 --- a/test/uri/test_parser.rb +++ b/test/uri/test_parser.rb @@ -69,8 +69,8 @@ def test_raise_bad_uri_for_integer end end - def test_unescape - p1 = URI::Parser.new + def test_rfc2822_unescape + 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)))