Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Fix encoding of modified return value
  • Loading branch information
k0kubun committed Dec 20, 2015
commit 21628354686e95d4ed7f327c967a9347468e3819
1 change: 1 addition & 0 deletions ext/cgi/escape/escape.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ optimized_escape_html(VALUE str)

if (modified) {
rb_str_cat(dest, cstr + beg, len - beg);
rb_enc_associate(dest, rb_enc_get(str));
return dest;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the encoding of str is ignored and dest is always ASCII-8BIT.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed it to associate original encoding and added test case for it in k0kubun@2162835.

} else {
return str;
Expand Down
6 changes: 6 additions & 0 deletions test/cgi/test_cgi_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ def test_cgi_escapeHTML
assert_equal(CGI::escapeHTML("'&\"><"),"&#39;&amp;&quot;&gt;&lt;")
end

def test_cgi_escape_html_preserve_encoding
assert_equal(Encoding::US_ASCII, CGI::escapeHTML("'&\"><".force_encoding("US-ASCII")).encoding)
assert_equal(Encoding::ASCII_8BIT, CGI::escapeHTML("'&\"><".force_encoding("ASCII-8BIT")).encoding)
assert_equal(Encoding::UTF_8, CGI::escapeHTML("'&\"><".force_encoding("UTF-8")).encoding)
end

def test_cgi_unescapeHTML
assert_equal(CGI::unescapeHTML("&#39;&amp;&quot;&gt;&lt;"),"'&\"><")
end
Expand Down