Skip to content

Commit

Permalink
Merge pull request #114 from ruby/warn-compatibility-methods
Browse files Browse the repository at this point in the history
Warn compatibility methods in RFC3986_PARSER
  • Loading branch information
hsbt authored Aug 8, 2024
2 parents c2fdec0 + 898b889 commit 28b9630
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/uri/generic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions lib/uri/rfc3986_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions test/uri/test_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down

0 comments on commit 28b9630

Please sign in to comment.