From fc63219087f9317f08e97a319af1146a46caa7b1 Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 4 Jun 2013 13:09:42 -0700 Subject: [PATCH] Merge pull request #173 from jsw0528/master fix `can't convert Fixnum into String` for `replace` --- lib/liquid/standardfilters.rb | 4 ++-- test/liquid/standard_filter_test.rb | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 17ae4e0..bc2b905 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -107,12 +107,12 @@ module Liquid # Replace occurrences of a string with another def replace(input, string, replacement = '') - input.to_s.gsub(string, replacement) + input.to_s.gsub(string, replacement.to_s) end # Replace the first occurrences of a string with another def replace_first(input, string, replacement = '') - input.to_s.sub(string, replacement) + input.to_s.sub(string, replacement.to_s) end # remove a substring diff --git a/test/liquid/standard_filter_test.rb b/test/liquid/standard_filter_test.rb index bf47f5d..05e4993 100644 --- a/test/liquid/standard_filter_test.rb +++ b/test/liquid/standard_filter_test.rb @@ -157,9 +157,9 @@ class StandardFiltersTest < Test::Unit::TestCase end def test_replace - assert_equal 'b b b b', @filters.replace("a a a a", 'a', 'b') - assert_equal 'b a a a', @filters.replace_first("a a a a", 'a', 'b') - assert_template_result 'b a a a', "{{ 'a a a a' | replace_first: 'a', 'b' }}" + assert_equal '2 2 2 2', @filters.replace('1 1 1 1', '1', 2) + assert_equal '2 1 1 1', @filters.replace_first('1 1 1 1', '1', 2) + assert_template_result '2 1 1 1', "{{ '1 1 1 1' | replace_first: '1', 2 }}" end def test_remove