Skip to content

Commit

Permalink
* lib/cgi/util.rb (CGI.escapeHTML): use '
Browse files Browse the repository at this point in the history
  [ruby-core:47221] [Bug #6861]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36766 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Aug 21, 2012
1 parent b0837c4 commit bbb6b5e
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
Wed Aug 22 07:27:00 2012 NARUSE, Yui <naruse@ruby-lang.org>

* lib/cgi/util.rb (CGI.escapeHTML): use &#39;
[ruby-core:47221] [Bug #6861]

Tue Aug 21 21:59:22 2012 Ayumu AIZAWA <ayumu.aizawa@gmail.com>

* lib/observer.rb: fix typo. https://github.com/ruby/ruby/pull/162 by
Expand Down
2 changes: 1 addition & 1 deletion lib/cgi/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def CGI::unescape(string,encoding=@@accept_charset)

# The set of special characters and their escaped values
TABLE_FOR_ESCAPE_HTML__ = {
"'" => '&#x27;',
"'" => '&#39;',
'&' => '&amp;',
'"' => '&quot;',
'<' => '&lt;',
Expand Down
4 changes: 2 additions & 2 deletions test/cgi/test_cgi_util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,11 @@ def test_cgi_pretty
end

def test_cgi_escapeHTML
assert_equal(CGI::escapeHTML("'&\"><"),"&#x27;&amp;&quot;&gt;&lt;")
assert_equal(CGI::escapeHTML("'&\"><"),"&#39;&amp;&quot;&gt;&lt;")
end

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

end
3 changes: 1 addition & 2 deletions test/erb/test_erb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ def test_with_filename_and_safe_level
end

def test_html_escape
# TODO: &apos; should be changed to &#x27;
assert_equal(" !&quot;\#$%&amp;&#x27;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
assert_equal(" !&quot;\#$%&amp;&#39;()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~",
ERB::Util.html_escape(" !\"\#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~"))

assert_equal("", ERB::Util.html_escape(""))
Expand Down

2 comments on commit bbb6b5e

@kalys
Copy link

@kalys kalys commented on bbb6b5e Sep 3, 2012

Choose a reason for hiding this comment

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

Why is &#39; preferable than &#x27;?

@knu
Copy link
Member

@knu knu commented on bbb6b5e Sep 3, 2012

Choose a reason for hiding this comment

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

Because it is shorter and is supported by a wider range of browsers, I guess.

The hexadecimal form is relatively new, introduced in HTML 4.0 while the decimal form dates back to the SGML era.

Please sign in to comment.