Project

General

Profile

Bug #14586 ยป rfc2396-uri-encoding.patch

kivikakk (Asherah Connor), 03/08/2018 01:53 AM

View differences:

lib/uri/rfc2396_parser.rb
#
# :call-seq:
# unescape( str )
# unescape( str, unsafe )
# unescape( str, escaped )
#
# == Args
#
# +str+::
# String to remove escapes from
# +unsafe+::
# +escaped+::
# Regexp to apply. Defaults to self.regexp[:ESCAPED]
#
# == Description
......
# Removes escapes from +str+
#
def unescape(str, escaped = @regexp[:ESCAPED])
str.gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(str.encoding)
enc = str.encoding
str.dup.force_encoding(Encoding::ASCII_8BIT).gsub(escaped) { [$&[1, 2].hex].pack('C') }.force_encoding(enc)
end
@@to_s = Kernel.instance_method(:to_s)
test/uri/test_parser.rb
URI.parse(1)
end
end
def test_unescape
p1 = URI::Parser.new
assert_equal("\xe3\x83\x90", p1.unescape("\xe3\x83\x90"))
assert_equal("\xe3\x83\x90", p1.unescape('%e3%83%90'))
assert_equal("\xe3\x83\x90\xe3\x83\x90", p1.unescape("\xe3\x83\x90%e3%83%90"))
end
end
    (1-1/1)