Fix html_escape failure with frozen strings

Closes #652
This commit is contained in:
Norman Clarke 2013-03-21 00:06:43 -03:00
parent 8aa89a3084
commit 8241fb228b
2 changed files with 10 additions and 4 deletions

View File

@ -587,14 +587,12 @@ MESSAGE
if RUBY_VERSION >= '1.9'
def html_escape(text)
text = text.to_s
text.gsub!(HTML_ESCAPE_REGEX, HTML_ESCAPE)
text
text.gsub(HTML_ESCAPE_REGEX, HTML_ESCAPE)
end
else
def html_escape(text)
text = text.to_s
text.gsub!(HTML_ESCAPE_REGEX) {|s| HTML_ESCAPE[s]}
text
text.gsub(HTML_ESCAPE_REGEX) {|s| HTML_ESCAPE[s]}
end
end

View File

@ -497,6 +497,14 @@ HAML
assert_equal "&quot;&gt;&lt;&amp;", Haml::Helpers.html_escape('"><&')
end
def test_html_escape_should_work_on_frozen_strings
begin
assert Haml::Helpers.html_escape('foo'.freeze)
rescue => e
flunk e.message
end
end
def test_html_escape_encoding
old_stderr, $stderr = $stderr, StringIO.new
string = "\"><&\u00e9" # if you're curious, u00e9 is "LATIN SMALL LETTER E WITH ACUTE"