Fix escape_once filter

This commit is contained in:
Gaurav Chande
2013-12-01 20:35:25 -05:00
parent 5ce36f79e9
commit 5e8f2f8bd0
2 changed files with 4 additions and 4 deletions

View File

@@ -4,6 +4,8 @@ require 'bigdecimal'
module Liquid
module StandardFilters
HTML_ESCAPE = { '&' => '&amp;', '>' => '&gt;', '<' => '&lt;', '"' => '&quot;', "'" => '&#39;' }
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
# Return the size of an array or of an string
def size(input)
@@ -31,9 +33,7 @@ module Liquid
end
def escape_once(input)
ActionView::Helpers::TagHelper.escape_once(input)
rescue NameError
input
input.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
end
alias_method :h, :escape

View File

@@ -89,7 +89,7 @@ class StandardFiltersTest < Test::Unit::TestCase
end
def test_escape_once
assert_equal '&lt;strong&gt;', @filters.escape_once(@filters.escape('<strong>'))
assert_equal '&lt;strong&gt;Hulk&lt;/strong&gt;', @filters.escape_once('&lt;strong&gt;Hulk</strong>')
end
def test_truncatewords