mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-26 13:45:13 -07:00
Preserve existing strip_html behaviour for weird inputs
This commit is contained in:
@@ -11,12 +11,12 @@ module Liquid
|
|||||||
"'".freeze => '''.freeze
|
"'".freeze => '''.freeze
|
||||||
}
|
}
|
||||||
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
|
||||||
STRIP_HTML = Regexp.union(
|
STRIP_HTML_BLOCKS = Regexp.union(
|
||||||
/<script.*?<\/script>/m,
|
/<script.*?<\/script>/m,
|
||||||
/<!--.*?-->/m,
|
/<!--.*?-->/m,
|
||||||
/<style.*?<\/style>/m,
|
/<style.*?<\/style>/m
|
||||||
/<.*?>/m
|
|
||||||
)
|
)
|
||||||
|
STRIP_HTML_TAGS = /<.*?>/m
|
||||||
|
|
||||||
# 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)
|
||||||
@@ -108,7 +108,10 @@ module Liquid
|
|||||||
end
|
end
|
||||||
|
|
||||||
def strip_html(input)
|
def strip_html(input)
|
||||||
input.to_s.gsub(STRIP_HTML, ''.freeze)
|
empty = ''.freeze
|
||||||
|
result = input.to_s.gsub(STRIP_HTML_BLOCKS, empty)
|
||||||
|
result.gsub!(STRIP_HTML_TAGS, empty)
|
||||||
|
result
|
||||||
end
|
end
|
||||||
|
|
||||||
# Remove all newlines from the string
|
# Remove all newlines from the string
|
||||||
|
|||||||
@@ -177,6 +177,9 @@ class StandardFiltersTest < Minitest::Test
|
|||||||
assert_equal 'test', @filters.strip_html("<div\nclass='multiline'>test</div>")
|
assert_equal 'test', @filters.strip_html("<div\nclass='multiline'>test</div>")
|
||||||
assert_equal 'test', @filters.strip_html("<!-- foo bar \n test -->test")
|
assert_equal 'test', @filters.strip_html("<!-- foo bar \n test -->test")
|
||||||
assert_equal '', @filters.strip_html(nil)
|
assert_equal '', @filters.strip_html(nil)
|
||||||
|
|
||||||
|
# Quirk of the existing implementation
|
||||||
|
assert_equal 'foo;', @filters.strip_html("<<<script </script>script>foo;</script>")
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_join
|
def test_join
|
||||||
|
|||||||
Reference in New Issue
Block a user