mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Fix escape_once filter
This commit is contained in:
@@ -4,6 +4,8 @@ require 'bigdecimal'
|
|||||||
module Liquid
|
module Liquid
|
||||||
|
|
||||||
module StandardFilters
|
module StandardFilters
|
||||||
|
HTML_ESCAPE = { '&' => '&', '>' => '>', '<' => '<', '"' => '"', "'" => ''' }
|
||||||
|
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
||||||
|
|
||||||
# Return the size of an array or of an string
|
# Return the size of an array or of an string
|
||||||
def size(input)
|
def size(input)
|
||||||
@@ -31,9 +33,7 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def escape_once(input)
|
def escape_once(input)
|
||||||
ActionView::Helpers::TagHelper.escape_once(input)
|
input.to_s.gsub(HTML_ESCAPE_ONCE_REGEXP, HTML_ESCAPE)
|
||||||
rescue NameError
|
|
||||||
input
|
|
||||||
end
|
end
|
||||||
|
|
||||||
alias_method :h, :escape
|
alias_method :h, :escape
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_escape_once
|
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
|
end
|
||||||
|
|
||||||
def test_truncatewords
|
def test_truncatewords
|
||||||
|
|||||||
Reference in New Issue
Block a user