From 6e967f7f3a26447f5a5708031ee8327635f3598c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?w=C7=92=5Fis=E7=A5=9E=E4=BB=99?= Date: Wed, 6 Feb 2013 12:55:35 +0800 Subject: [PATCH 1/2] fix `can't convert Fixnum into String` --- lib/liquid/standardfilters.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/liquid/standardfilters.rb b/lib/liquid/standardfilters.rb index 651216ac..7072b081 100644 --- a/lib/liquid/standardfilters.rb +++ b/lib/liquid/standardfilters.rb @@ -102,12 +102,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 From 17dd85868d1653c02ab8d27d584018b497312ae9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?w=C7=92=5Fis=E7=A5=9E=E4=BB=99?= Date: Thu, 21 Feb 2013 10:52:46 +0800 Subject: [PATCH 2/2] add tests for replace filter --- test/liquid/standard_filter_test.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/liquid/standard_filter_test.rb b/test/liquid/standard_filter_test.rb index 2ee7ae8d..72a29611 100644 --- a/test/liquid/standard_filter_test.rb +++ b/test/liquid/standard_filter_test.rb @@ -119,9 +119,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