mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* lib/cgi.rb (CGI::escapeHTML): use gsub with Hash. [ruby-dev:33828]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15526 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
8dd8dfce21
commit
adc639bb26
2 changed files with 11 additions and 1 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Sun Feb 17 23:06:55 2008 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||||
|
|
||||||
|
* lib/cgi.rb (CGI::escapeHTML): use gsub with Hash. [ruby-dev:33828]
|
||||||
|
|
||||||
Sun Feb 17 21:38:21 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
Sun Feb 17 21:38:21 2008 NARUSE, Yui <naruse@ruby-lang.org>
|
||||||
|
|
||||||
* encoding.c (ENC_CODERANGE_AND): fix broken case. [ruby-dev:33826]
|
* encoding.c (ENC_CODERANGE_AND): fix broken case. [ruby-dev:33826]
|
||||||
|
|
|
@ -355,12 +355,18 @@ class CGI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
TABLE_FOR_ESCAPE_HTML__ = {
|
||||||
|
'&' => '&',
|
||||||
|
'"' => '"',
|
||||||
|
'<' => '<',
|
||||||
|
'>' => '>',
|
||||||
|
}
|
||||||
|
|
||||||
# Escape special characters in HTML, namely &\"<>
|
# Escape special characters in HTML, namely &\"<>
|
||||||
# CGI::escapeHTML('Usage: foo "bar" <baz>')
|
# CGI::escapeHTML('Usage: foo "bar" <baz>')
|
||||||
# # => "Usage: foo "bar" <baz>"
|
# # => "Usage: foo "bar" <baz>"
|
||||||
def CGI::escapeHTML(string)
|
def CGI::escapeHTML(string)
|
||||||
string.gsub(/&/, '&').gsub(/\"/, '"').gsub(/>/, '>').gsub(/</, '<')
|
string.gsub(/[&\"<>]/, TABLE_FOR_ESCAPE_HTML__)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue