Single regexp for strip_html

This commit is contained in:
printercu
2018-09-27 17:13:35 +03:00
committed by GitHub
parent 53b8babf52
commit 479d8fb4a4

View File

@@ -11,6 +11,12 @@ module Liquid
"'".freeze => '''.freeze
}
HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/
STRIP_HTML = Regexp.union(
/<script.*?<\/script>/m,
/<!--.*?-->/m,
/<style.*?<\/style>/m,
/<.*?>/m,
)
# Return the size of an array or of an string
def size(input)
@@ -102,8 +108,7 @@ module Liquid
end
def strip_html(input)
empty = ''.freeze
input.to_s.gsub(/<script.*?<\/script>/m, empty).gsub(/<!--.*?-->/m, empty).gsub(/<style.*?<\/style>/m, empty).gsub(/<.*?>/m, empty)
input.to_s.gsub(STRIP_HTML, ''.freeze)
end
# Remove all newlines from the string