mirror of
https://github.com/kemko/liquid.git
synced 2026-01-01 15:55:40 +03:00
Fix escape_once filter
This commit is contained in:
@@ -4,6 +4,8 @@ require 'bigdecimal'
|
||||
module Liquid
|
||||
|
||||
module StandardFilters
|
||||
HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' }
|
||||
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
|
||||
|
||||
@@ -89,7 +89,7 @@ class StandardFiltersTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_escape_once
|
||||
assert_equal '<strong>', @filters.escape_once(@filters.escape('<strong>'))
|
||||
assert_equal '<strong>Hulk</strong>', @filters.escape_once('<strong>Hulk</strong>')
|
||||
end
|
||||
|
||||
def test_truncatewords
|
||||
|
||||
Reference in New Issue
Block a user