diff --git a/lib/erb.rb b/lib/erb.rb index bb47943a868a0c..09623f07c21b4d 100644 --- a/lib/erb.rb +++ b/lib/erb.rb @@ -896,6 +896,16 @@ class ERB # A utility module for conversion routines, often handy in HTML generation. module Util public + + # The set of special characters and their escaped values + TABLE_FOR_ESCAPE_HTML__ = { + "'" => ''', + '&' => '&', + '"' => '"', + '<' => '<', + '>' => '>', + } + # # A utility method for escaping HTML tag characters in _s_. # @@ -909,7 +919,7 @@ module Util # is a > 0 & a < 10? # def html_escape(s) - s.to_s.gsub(/&/, "&").gsub(/\"/, """).gsub(/>/, ">").gsub(/]/, TABLE_FOR_ESCAPE_HTML__) end alias h html_escape module_function :h