mirror of
https://github.com/Shopify/liquid.git
synced 2026-10-04 01:25:14 -07:00
fix variable output with quoted strings containing pipe ("|") characters
This commit is contained in:
@@ -11,16 +11,17 @@ module Liquid
|
|||||||
# {{ user | link }}
|
# {{ user | link }}
|
||||||
#
|
#
|
||||||
class Variable
|
class Variable
|
||||||
|
FilterParser = /(?:#{FilterSeparator}|(?:\s*(?!(?:#{FilterSeparator}))(?:#{QuotedFragment}|\S+)\s*)+)/
|
||||||
attr_accessor :filters, :name
|
attr_accessor :filters, :name
|
||||||
|
|
||||||
def initialize(markup)
|
def initialize(markup)
|
||||||
@markup = markup
|
@markup = markup
|
||||||
@name = nil
|
@name = nil
|
||||||
@filters = []
|
@filters = []
|
||||||
if match = markup.match(/\s*(#{QuotedFragment})/)
|
if match = markup.match(/\s*(#{QuotedFragment})(.*)/)
|
||||||
@name = match[1]
|
@name = match[1]
|
||||||
if markup.match(/#{FilterSeparator}\s*(.*)/)
|
if match[2].match(/#{FilterSeparator}\s*(.*)/)
|
||||||
filters = Regexp.last_match(1).split(/#{FilterSeparator}/)
|
filters = Regexp.last_match(1).scan(FilterParser)
|
||||||
filters.each do |f|
|
filters.each do |f|
|
||||||
if matches = f.match(/\s*(\w+)/)
|
if matches = f.match(/\s*(\w+)/)
|
||||||
filtername = matches[1]
|
filtername = matches[1]
|
||||||
|
|||||||
@@ -117,6 +117,10 @@ class StandardFiltersTest < Test::Unit::TestCase
|
|||||||
assert_template_result 'a a a', "{{ 'a a a a' | remove_first: 'a ' }}"
|
assert_template_result 'a a a', "{{ 'a a a a' | remove_first: 'a ' }}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_pipes_in_string_arguments
|
||||||
|
assert_template_result 'foobar', "{{ 'foo|bar' | remove: '|' }}"
|
||||||
|
end
|
||||||
|
|
||||||
def test_strip_newlines
|
def test_strip_newlines
|
||||||
assert_template_result 'abc', "{{ source | strip_newlines }}", 'source' => "a\nb\nc"
|
assert_template_result 'abc', "{{ source | strip_newlines }}", 'source' => "a\nb\nc"
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user