From 23203c01221dcfd09d077bb6aab2d62b0e6be24f Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Tue, 21 May 2013 14:08:40 -0400 Subject: [PATCH] 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. --- lib/liquid/variable.rb | 4 ++-- test/liquid/variable_test.rb | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index 5758fb0..883e3ea 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -23,9 +23,9 @@ module Liquid if match[2].match(/#{FilterSeparator}\s*(.*)/o) filters = Regexp.last_match(1).scan(FilterParser) filters.each do |f| - if matches = f.match(/\s*(\w+)(?:\s*#{FilterArgumentSeparator}(.*))?/) + if matches = f.match(/\s*(\w+)/) 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] end end diff --git a/test/liquid/variable_test.rb b/test/liquid/variable_test.rb index 217a885..7554e00 100644 --- a/test/liquid/variable_test.rb +++ b/test/liquid/variable_test.rb @@ -113,6 +113,12 @@ class VariableTest < Test::Unit::TestCase assert_equal 'hello', var.name assert_equal [['things',["greeting: \"world\"","farewell: 'goodbye'"]]], var.filters 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