Revert "Use replacement string for replace filters literally (#924)"

This reverts commit 27c91203ab.
This commit is contained in:
Justin Li
2017-12-04 15:07:59 -05:00
parent 2ad7a37d44
commit e6ba6ee87b
2 changed files with 2 additions and 6 deletions

View File

@@ -201,14 +201,12 @@ module Liquid
# Replace occurrences of a string with another
def replace(input, string, replacement = ''.freeze)
replacement = replacement.to_s
input.to_s.gsub(string.to_s) { replacement }
input.to_s.gsub(string.to_s, replacement.to_s)
end
# Replace the first occurrences of a string with another
def replace_first(input, string, replacement = ''.freeze)
replacement = replacement.to_s
input.to_s.sub(string.to_s) { replacement }
input.to_s.sub(string.to_s, replacement.to_s)
end
# remove a substring

View File

@@ -362,10 +362,8 @@ class StandardFiltersTest < Minitest::Test
def test_replace
assert_equal '2 2 2 2', @filters.replace('1 1 1 1', '1', 2)
assert_equal '2 2 2 2', @filters.replace('1 1 1 1', 1, 2)
assert_equal "\\& \\& \\& \\&", @filters.replace('1 1 1 1', '1', "\\&")
assert_equal '2 1 1 1', @filters.replace_first('1 1 1 1', '1', 2)
assert_equal '2 1 1 1', @filters.replace_first('1 1 1 1', 1, 2)
assert_equal '\\& 1 1 1', @filters.replace_first("1 1 1 1", '1', "\\&")
assert_template_result '2 1 1 1', "{{ '1 1 1 1' | replace_first: '1', 2 }}"
end