Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure strings are not enumerated in Ruby 1.8

  • Loading branch information...
commit 006c37a8e7086af8226f251ee8769393f83e8e23 1 parent 9c74f2e
@defunkt defunkt authored
Showing with 10 additions and 1 deletion.
  1. +1 −1  lib/mustache/generator.rb
  2. +9 −0 test/mustache_test.rb
View
2  lib/mustache/generator.rb
@@ -105,7 +105,7 @@ def on_section(name, content, raw)
Mustache::Template.new(v.call(#{raw.inspect}).to_s).render(ctx.dup)
else
# Shortcut when passed non-array
- v = [v] if v.respond_to?(:has_key?) || !v.respond_to?(:map) || v.is_a?(Struct)
+ v = [v] unless v.is_a?(Array) || defined?(Enumerator) && v.is_a?(Enumerator)
v.map { |h| ctx.push(h); r = #{code}; ctx.pop; r }.join
end
View
9 test/mustache_test.rb
@@ -57,6 +57,15 @@ def test_single_line_sections
assert_equal %Q'<p class="flash-notice" style="display: none;">', instance.render
end
+ def test_strings_as_sections_do_not_enumerate
+ instance = Mustache.new
+ instance[:contact] = "Call 1-888-FLOWERS\nAsk for Johnson."
+ instance.template = "{{#contact}}<div id='contact'>{{contact}}</div>{{/contact}}"
+
+ assert_equal "<div id='contact'>Call 1-888-FLOWERS\nAsk for Johnson.</div>",
+ instance.render
+ end
+
def test_sassy_single_line_sections
instance = Mustache.new
instance[:full_time] = true
Please sign in to comment.
Something went wrong with that request. Please try again.