diff --git a/lib/liquid/tags/for.rb b/lib/liquid/tags/for.rb index cd0b7649..76aaa6f3 100644 --- a/lib/liquid/tags/for.rb +++ b/lib/liquid/tags/for.rb @@ -76,9 +76,6 @@ module Liquid collection = context.evaluate(@collection_name) collection = collection.to_a if collection.is_a?(Range) - # Maintains Ruby 1.8.7 String#each behaviour on 1.9 - return render_else(context) unless iterable?(collection) - from = if @from == :continue for_offsets[@name].to_i else @@ -189,10 +186,6 @@ module Liquid def render_else(context) @else_block ? @else_block.render(context) : ''.freeze end - - def iterable?(collection) - collection.respond_to?(:each) || Utils.non_blank_string?(collection) - end end Template.register_tag('for'.freeze, For) diff --git a/lib/liquid/utils.rb b/lib/liquid/utils.rb index ed1e9d91..ba8a2cac 100644 --- a/lib/liquid/utils.rb +++ b/lib/liquid/utils.rb @@ -8,16 +8,15 @@ module Liquid end end - def self.non_blank_string?(collection) - collection.is_a?(String) && collection != ''.freeze - end - def self.slice_collection_using_each(collection, from, to) segments = [] index = 0 # Maintains Ruby 1.8.7 String#each behaviour on 1.9 - return [collection] if non_blank_string?(collection) + if collection.is_a?(String) + return collection.empty? ? [] : [collection] + end + return [] unless collection.respond_to?(:each) collection.each do |item| if to && to <= index diff --git a/test/integration/tags/table_row_test.rb b/test/integration/tags/table_row_test.rb index 6405a9c4..d7bc14cf 100644 --- a/test/integration/tags/table_row_test.rb +++ b/test/integration/tags/table_row_test.rb @@ -57,4 +57,8 @@ class TableRowTest < Minitest::Test '{% tablerow n in numbers cols:3 offset:1 limit:6%} {{n}} {% endtablerow %}', 'numbers' => [0, 1, 2, 3, 4, 5, 6, 7]) end + + def test_blank_string_not_iterable + assert_template_result("