mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 16:25:42 +03:00
Ruby 1.8 compatibility fix: Ensure for-loop on an empty string does not enter for-body.
This commit is contained in:
@@ -76,7 +76,7 @@ module Liquid
|
||||
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 collection.respond_to?(:each) or collection.is_a?(String)
|
||||
return render_else(context) unless iterable?(collection)
|
||||
|
||||
from = if @attributes['offset'] == 'continue'
|
||||
context.registers[:for][@name].to_i
|
||||
@@ -150,6 +150,9 @@ module Liquid
|
||||
return @else_block ? [render_all(@else_block, context)] : ''
|
||||
end
|
||||
|
||||
def iterable?(collection)
|
||||
collection.respond_to?(:each) || (collection.is_a?(String) && collection != '')
|
||||
end
|
||||
end
|
||||
|
||||
Template.register_tag('for', For)
|
||||
|
||||
@@ -195,4 +195,8 @@ HERE
|
||||
'{{val}}{%endfor%}',
|
||||
'string' => "test string")
|
||||
end
|
||||
|
||||
def test_blank_string_not_iterable
|
||||
assert_template_result('', "{% for char in characters %}I WILL NOT BE OUTPUT{% endfor %}", 'characters' => '')
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user