fix variable output with quoted strings containing pipe ("|") characters

This commit is contained in:
James MacAulay
2009-09-23 15:54:25 -04:00
parent 11dc18bfdf
commit cbf8986745
2 changed files with 8 additions and 3 deletions

View File

@@ -11,16 +11,17 @@ module Liquid
# {{ user | link }}
#
class Variable
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?!(?:#{FilterSeparator}))(?:#{QuotedFragment}|\S+)\s*)+)/
attr_accessor :filters, :name
def initialize(markup)
@markup = markup
@name = nil
@filters = []
if match = markup.match(/\s*(#{QuotedFragment})/)
if match = markup.match(/\s*(#{QuotedFragment})(.*)/)
@name = match[1]
if markup.match(/#{FilterSeparator}\s*(.*)/)
filters = Regexp.last_match(1).split(/#{FilterSeparator}/)
if match[2].match(/#{FilterSeparator}\s*(.*)/)
filters = Regexp.last_match(1).scan(FilterParser)
filters.each do |f|
if matches = f.match(/\s*(\w+)/)
filtername = matches[1]

View File

@@ -116,6 +116,10 @@ class StandardFiltersTest < Test::Unit::TestCase
assert_equal 'a a a', @filters.remove_first("a a a a", 'a ')
assert_template_result 'a a a', "{{ 'a a a a' | remove_first: 'a ' }}"
end
def test_pipes_in_string_arguments
assert_template_result 'foobar', "{{ 'foo|bar' | remove: '|' }}"
end
def test_strip_newlines
assert_template_result 'abc', "{{ source | strip_newlines }}", 'source' => "a\nb\nc"