mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
cgi/util.rb: Don't escape tilde in #escape
to make it compatible with ERB::Util.url_encode. ext/cgi/escape/escape.c: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58773 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
53127c2410
commit
e1b4327545
3 changed files with 8 additions and 2 deletions
|
@ -196,7 +196,7 @@ url_unreserved_char(unsigned char c)
|
||||||
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J':
|
case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I': case 'J':
|
||||||
case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T':
|
case 'K': case 'L': case 'M': case 'N': case 'O': case 'P': case 'Q': case 'R': case 'S': case 'T':
|
||||||
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
|
case 'U': case 'V': case 'W': case 'X': case 'Y': case 'Z':
|
||||||
case '-': case '.': case '_':
|
case '-': case '.': case '_': case '~':
|
||||||
return 1;
|
return 1;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -11,7 +11,7 @@ module CGI::Util
|
||||||
# # => "%27Stop%21%27+said+Fred"
|
# # => "%27Stop%21%27+said+Fred"
|
||||||
def escape(string)
|
def escape(string)
|
||||||
encoding = string.encoding
|
encoding = string.encoding
|
||||||
string.b.gsub(/([^ a-zA-Z0-9_.-]+)/) do |m|
|
string.b.gsub(/([^ a-zA-Z0-9_.\-~]+)/) do |m|
|
||||||
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
'%' + m.unpack('H2' * m.bytesize).join('%').upcase
|
||||||
end.tr(' ', '+').force_encoding(encoding)
|
end.tr(' ', '+').force_encoding(encoding)
|
||||||
end
|
end
|
||||||
|
|
|
@ -29,6 +29,12 @@ class CGIUtilTest < Test::Unit::TestCase
|
||||||
assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93'.ascii_only?, CGI::escape(@str1).ascii_only?) if defined?(::Encoding)
|
assert_equal('%26%3C%3E%22+%E3%82%86%E3%82%93%E3%82%86%E3%82%93'.ascii_only?, CGI::escape(@str1).ascii_only?) if defined?(::Encoding)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_cgi_escape_with_unreserved_characters
|
||||||
|
assert_equal("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~",
|
||||||
|
CGI::escape("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~"),
|
||||||
|
"should not escape any unreserved characters, as per RFC3986 Section 2.3")
|
||||||
|
end
|
||||||
|
|
||||||
def test_cgi_escape_with_invalid_byte_sequence
|
def test_cgi_escape_with_invalid_byte_sequence
|
||||||
assert_nothing_raised(ArgumentError) do
|
assert_nothing_raised(ArgumentError) do
|
||||||
assert_equal('%C0%3C%3C', CGI::escape("\xC0\<\<".dup.force_encoding("UTF-8")))
|
assert_equal('%C0%3C%3C', CGI::escape("\xC0\<\<".dup.force_encoding("UTF-8")))
|
||||||
|
|
Loading…
Reference in a new issue