mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-15 08:50:45 -07:00
Revert "Instrument usage of bug with iteration of String with offset or 0 limit (#1667)"
This reverts commit c743936a78.
This commit is contained in:
committed by
GitHub
parent
e804f36681
commit
65899ee261
+1
-5
@@ -16,11 +16,7 @@ module Liquid
|
|||||||
|
|
||||||
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
|
# Maintains Ruby 1.8.7 String#each behaviour on 1.9
|
||||||
if collection.is_a?(String)
|
if collection.is_a?(String)
|
||||||
return [] if collection.empty?
|
return collection.empty? ? [] : [collection]
|
||||||
if from > 0 || to == 0
|
|
||||||
Usage.increment("string_slice_bug")
|
|
||||||
end
|
|
||||||
return [collection]
|
|
||||||
end
|
end
|
||||||
return [] unless collection.respond_to?(:each)
|
return [] unless collection.respond_to?(:each)
|
||||||
|
|
||||||
|
|||||||
@@ -12,34 +12,4 @@ class ForTagUnitTest < Minitest::Test
|
|||||||
template = Liquid::Template.parse('{% for item in items %}FOR{% else %}ELSE{% endfor %}')
|
template = Liquid::Template.parse('{% for item in items %}FOR{% else %}ELSE{% endfor %}')
|
||||||
assert_equal(['FOR', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten)
|
assert_equal(['FOR', 'ELSE'], template.root.nodelist[0].nodelist.map(&:nodelist).flatten)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_for_string_slice_bug_usage
|
|
||||||
template = Liquid::Template.parse("{% for x in str, offset: 1 %}{{ x }},{% endfor %}")
|
|
||||||
assert_usage("string_slice_bug") do
|
|
||||||
assert_equal("abc,", template.render({ "str" => "abc" }))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_for_string_0_limit_usage
|
|
||||||
template = Liquid::Template.parse("{% for x in str, limit: 0 %}{{ x }},{% endfor %}")
|
|
||||||
assert_usage("string_slice_bug") do
|
|
||||||
assert_equal("abc,", template.render({ "str" => "abc" }))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def test_for_string_no_slice_usage
|
|
||||||
template = Liquid::Template.parse("{% for x in str, offset: 0, limit: 1 %}{{ x }},{% endfor %}")
|
|
||||||
assert_usage("string_slice_bug", times: 0) do
|
|
||||||
assert_equal("abc,", template.render({ "str" => "abc" }))
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
private
|
|
||||||
|
|
||||||
def assert_usage(name, times: 1, &block)
|
|
||||||
count = 0
|
|
||||||
result = Liquid::Usage.stub(:increment, ->(n) { count += 1 if n == name }, &block)
|
|
||||||
assert_equal(times, count)
|
|
||||||
result
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user