From 479d8fb4a40db6947670fd6b1386cb3e2d612883 Mon Sep 17 00:00:00 2001 From: printercu Date: Thu, 27 Sep 2018 17:13:35 +0300 Subject: [PATCH] Single regexp for strip_html --- lib/liquid/standardfilters.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index c5dbcb8..3d939ae 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -11,6 +11,12 @@ module Liquid "'".freeze => '''.freeze } HTML_ESCAPE_ONCE_REGEXP = /["><']|&(?!([a-zA-Z]+|(#\d+));)/ + STRIP_HTML = Regexp.union( + //m, + //m, + //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(//m, empty).gsub(//m, empty).gsub(//m, empty).gsub(/<.*?>/m, empty) + input.to_s.gsub(STRIP_HTML, ''.freeze) end # Remove all newlines from the string