mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-12 23:40:45 -07:00
Fix some old templates that abused colon as an argument separator.
This is a fallback for keyword argument parsing since this feature broke old templates that accidentally used a colon as a filter argument separator.
This commit is contained in:
@@ -23,9 +23,9 @@ module Liquid
|
|||||||
if match[2].match(/#{FilterSeparator}\s*(.*)/o)
|
if match[2].match(/#{FilterSeparator}\s*(.*)/o)
|
||||||
filters = Regexp.last_match(1).scan(FilterParser)
|
filters = Regexp.last_match(1).scan(FilterParser)
|
||||||
filters.each do |f|
|
filters.each do |f|
|
||||||
if matches = f.match(/\s*(\w+)(?:\s*#{FilterArgumentSeparator}(.*))?/)
|
if matches = f.match(/\s*(\w+)/)
|
||||||
filtername = matches[1]
|
filtername = matches[1]
|
||||||
filterargs = matches[2].to_s.scan(/(?:\A|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o).flatten
|
filterargs = f.scan(/(?:#{FilterArgumentSeparator}|#{ArgumentSeparator})\s*((?:\w+\s*\:\s*)?#{QuotedFragment})/o).flatten
|
||||||
@filters << [filtername, filterargs]
|
@filters << [filtername, filterargs]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -113,6 +113,12 @@ class VariableTest < Test::Unit::TestCase
|
|||||||
assert_equal 'hello', var.name
|
assert_equal 'hello', var.name
|
||||||
assert_equal [['things',["greeting: \"world\"","farewell: 'goodbye'"]]], var.filters
|
assert_equal [['things',["greeting: \"world\"","farewell: 'goodbye'"]]], var.filters
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_lax_filter_argument_parsing
|
||||||
|
var = Variable.new(%! number_of_comments | pluralize: 'comment': 'comments' !)
|
||||||
|
assert_equal 'number_of_comments', var.name
|
||||||
|
assert_equal [['pluralize',["'comment'","'comments'"]]], var.filters
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user