escape_once works on frozen strings.

That way, it works the same way as #html_escape and
ERB::Util.html_escape_once for which it acts as a replacement in Rails.

Furthermore, it is not obvious from the method name that the string
given as an argument is being changed.
This commit is contained in:
Patrik Metzmacher 2013-11-02 18:26:21 +01:00
parent 2887b24864
commit 5bb46925b2
3 changed files with 14 additions and 4 deletions

View File

@ -1,5 +1,9 @@
# Haml Changelog
* Helpers#escape_once works on frozen strings (as does
ERB::Util.html_escape_once for which it acts as a replacement in
Rails.
## 4.0.3
Released May 21, 2013 ([diff](https://github.com/haml/haml/compare/4.0.2...4.0.3)).

View File

@ -564,14 +564,12 @@ MESSAGE
# @return [String] The sanitized string
def escape_once(text)
text = text.to_s
text.gsub!(HTML_ESCAPE_ONCE_REGEX, HTML_ESCAPE)
text
text.gsub(HTML_ESCAPE_ONCE_REGEX, HTML_ESCAPE)
end
else
def escape_once(text)
text = text.to_s
text.gsub!(HTML_ESCAPE_ONCE_REGEX){|s| HTML_ESCAPE[s]}
text
text.gsub(HTML_ESCAPE_ONCE_REGEX){|s| HTML_ESCAPE[s]}
end
end

View File

@ -553,5 +553,13 @@ HAML
$stderr = old_stderr
end
def test_escape_once_should_work_on_frozen_strings
begin
Haml::Helpers.escape_once('foo'.freeze)
rescue => e
flunk e.message
end
end
end