mirror of
https://github.com/kemko/liquid.git
synced 2026-01-02 16:25:42 +03:00
Compare commits
7 Commits
styling-fi
...
tokenizer-
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
331b2a2e96 | ||
|
|
3ffae9a6e4 | ||
|
|
f4d134cd5c | ||
|
|
b667bcb48b | ||
|
|
2c14e0b2ba | ||
|
|
ca207ed93f | ||
|
|
ef13343591 |
@@ -1,5 +1,5 @@
|
||||
inherit_from:
|
||||
- https://shopify.github.io/ruby-style-guide/rubocop.yml
|
||||
- 'https://shopify.github.io/ruby-style-guide/rubocop.yml'
|
||||
- .rubocop_todo.yml
|
||||
|
||||
require: rubocop-performance
|
||||
@@ -8,9 +8,10 @@ Performance:
|
||||
Enabled: true
|
||||
|
||||
AllCops:
|
||||
TargetRubyVersion: 2.4
|
||||
Exclude:
|
||||
- 'vendor/bundle/**/*'
|
||||
|
||||
|
||||
Naming/MethodName:
|
||||
Exclude:
|
||||
- 'example/server/liquid_servlet.rb'
|
||||
- 'example/server/liquid_servlet.rb'
|
||||
|
||||
@@ -7,8 +7,6 @@ rvm:
|
||||
- &latest_ruby 2.6
|
||||
- 2.7
|
||||
- ruby-head
|
||||
- jruby-head
|
||||
- truffleruby
|
||||
|
||||
matrix:
|
||||
include:
|
||||
@@ -17,8 +15,6 @@ matrix:
|
||||
name: Profiling Memory Usage
|
||||
allow_failures:
|
||||
- rvm: ruby-head
|
||||
- rvm: jruby-head
|
||||
- rvm: truffleruby
|
||||
|
||||
branches:
|
||||
only:
|
||||
|
||||
@@ -59,7 +59,7 @@ module Liquid
|
||||
end
|
||||
|
||||
def full_path(template_path)
|
||||
raise FileSystemError, "Illegal template name '#{template_path}'" unless template_path =~ %r{\A[^./][a-zA-Z0-9_/]+\z}
|
||||
raise FileSystemError, "Illegal template name '#{template_path}'" unless %r{\A[^./][a-zA-Z0-9_/]+\z}.match?(template_path)
|
||||
|
||||
full_path = if template_path.include?('/')
|
||||
File.join(root, File.dirname(template_path), @pattern % File.basename(template_path))
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
|
||||
module Liquid
|
||||
class StaticRegisters
|
||||
attr_reader :static_registers, :registers
|
||||
attr_reader :static, :registers
|
||||
|
||||
def initialize(registers = {})
|
||||
@static_registers = registers.is_a?(StaticRegisters) ? registers.static_registers : registers.freeze
|
||||
@static = registers.is_a?(StaticRegisters) ? registers.static : registers
|
||||
@registers = {}
|
||||
end
|
||||
|
||||
@@ -17,7 +17,7 @@ module Liquid
|
||||
if @registers.key?(key)
|
||||
@registers[key]
|
||||
else
|
||||
@static_registers[key]
|
||||
@static[key]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,7 +30,7 @@ module Liquid
|
||||
end
|
||||
|
||||
def key?(key)
|
||||
@registers.key?(key) || @static_registers.key?(key)
|
||||
@registers.key?(key) || @static.key?(key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ module Liquid
|
||||
protected
|
||||
|
||||
def ensure_valid_markup(tag_name, markup, parse_context)
|
||||
unless markup =~ Syntax
|
||||
unless Syntax.match?(markup)
|
||||
raise SyntaxError, parse_context.locale.t("errors.syntax.tag_unexpected_args", tag: tag_name)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -28,12 +28,84 @@ module Liquid
|
||||
|
||||
return @source.split("\n") if @for_liquid_tag
|
||||
|
||||
tokens = @source.split(TemplateParser)
|
||||
tokens = tokenize_new(@source)
|
||||
# tokens = @source.split(TemplateParser)
|
||||
|
||||
# removes the rogue empty element at the beginning of the array
|
||||
tokens.shift if tokens[0]&.empty?
|
||||
|
||||
tokens
|
||||
end
|
||||
|
||||
T_TAG_OPEN = "{%"
|
||||
T_VAR_OPEN = "{{"
|
||||
T_SIN_QUOT = "'"
|
||||
T_DOU_QUOT = '"'
|
||||
T_TAG_CLOS = "%}"
|
||||
T_VAR_CLOS = "}}"
|
||||
T_VAR_CLO2 = "}"
|
||||
|
||||
S_NIL = 0
|
||||
S_TAG = 1
|
||||
S_VAR = 2
|
||||
S_TAG_SIN = 3
|
||||
S_TAG_DOU = 4
|
||||
S_VAR_SIN = 5
|
||||
S_VAR_DOU = 6
|
||||
|
||||
def tokenize_new(source)
|
||||
output = []
|
||||
s = S_NIL
|
||||
current = +""
|
||||
source.split(/({%|{{|"|'|}}|%}|})/om).each do |t|
|
||||
if t == T_TAG_OPEN && s <= S_VAR
|
||||
s = S_TAG
|
||||
output << current
|
||||
current = t
|
||||
elsif t == T_VAR_OPEN && s <= S_VAR
|
||||
s = S_VAR
|
||||
output << current
|
||||
current = t
|
||||
elsif t == T_SIN_QUOT && s == S_TAG
|
||||
s = S_TAG_SIN
|
||||
current += t
|
||||
elsif t == T_SIN_QUOT && s == S_TAG_SIN
|
||||
s = S_TAG
|
||||
current += t
|
||||
elsif t == T_DOU_QUOT && s == S_TAG
|
||||
s = S_TAG_DOU
|
||||
current += t
|
||||
elsif t == T_DOU_QUOT && s == S_TAG_DOU
|
||||
s = S_TAG
|
||||
current += t
|
||||
elsif t == T_SIN_QUOT && s == S_VAR
|
||||
s = S_VAR_SIN
|
||||
current += t
|
||||
elsif t == T_SIN_QUOT && s == S_VAR_SIN
|
||||
s = S_VAR
|
||||
current += t
|
||||
elsif t == T_DOU_QUOT && s == S_VAR
|
||||
s = S_VAR_DOU
|
||||
current += t
|
||||
elsif t == T_DOU_QUOT && s == S_VAR_DOU
|
||||
s = S_VAR
|
||||
current += t
|
||||
elsif t == T_TAG_CLOS && s == S_TAG
|
||||
s = S_NIL
|
||||
current += t
|
||||
output << current
|
||||
current = +""
|
||||
elsif (t == T_VAR_CLOS || t == T_VAR_CLO2) && s == S_VAR
|
||||
s = S_NIL
|
||||
current += t
|
||||
output << current
|
||||
current = +""
|
||||
else
|
||||
current += t
|
||||
end
|
||||
end
|
||||
output << current unless current == ""
|
||||
output
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -52,7 +52,7 @@ module Liquid
|
||||
when Numeric
|
||||
obj
|
||||
when String
|
||||
obj.strip =~ /\A-?\d+\.\d+\z/ ? BigDecimal(obj) : obj.to_i
|
||||
/\A-?\d+\.\d+\z/.match?(obj.strip) ? BigDecimal(obj) : obj.to_i
|
||||
else
|
||||
if obj.respond_to?(:to_number)
|
||||
obj.to_number
|
||||
|
||||
19
test/integration/tags/assign_tag_test.rb
Normal file
19
test/integration/tags/assign_tag_test.rb
Normal file
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class AssignTagTest < Minitest::Test
|
||||
include Liquid
|
||||
|
||||
def test_assign
|
||||
assert_template_result('monkey', "{% assign foo = 'monkey' %}{{ foo }}")
|
||||
end
|
||||
|
||||
def test_string_with_end_tag
|
||||
assert_template_result("{% quoted %}", "{% assign string = '{% quoted %}' %}{{ string }}")
|
||||
end
|
||||
|
||||
def test_liquid_issue_701
|
||||
assert_template_result(" contents: _{% endraw %}_", "{% assign endraw = '{% endraw %}' %} contents: _{{endraw}}_")
|
||||
end
|
||||
end
|
||||
@@ -23,11 +23,17 @@ class RawTagTest < Minitest::Test
|
||||
assert_template_result ' Foobar {% {% {% ', '{% raw %} Foobar {% {% {% {% endraw %}'
|
||||
assert_template_result ' test {% raw %} {% endraw %}', '{% raw %} test {% raw %} {% {% endraw %}endraw %}'
|
||||
assert_template_result ' Foobar {{ invalid 1', '{% raw %} Foobar {{ invalid {% endraw %}{{ 1 }}'
|
||||
assert_template_result ' Foobar {{ invalid 12', '{% raw %} Foobar {{ invalid {% endraw %}{{ 1 }}{{ 2 }}'
|
||||
assert_template_result ' Foobar {{ invalid 1', '{% raw %} Foobar {{ invalid {% endraw %}{{ 1 }}'
|
||||
end
|
||||
|
||||
def test_nested_tag_in_raw
|
||||
assert_template_result '{{ {% test %} }}', '{% raw %}{{ {% test %} }}{% endraw %}'
|
||||
end
|
||||
|
||||
def test_invalid_raw
|
||||
assert_match_syntax_error(/tag was never closed/, '{% raw %} foo')
|
||||
assert_match_syntax_error(/Valid syntax/, '{% raw } foo {% endraw %}')
|
||||
assert_match_syntax_error(/was not properly terminated/, '{% raw } foo {% endraw %}')
|
||||
assert_match_syntax_error(/Valid syntax/, '{% raw } foo %}{% endraw %}')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -361,4 +361,9 @@ class TemplateTest < Minitest::Test
|
||||
result = t.render('x' => 1, 'y' => 5)
|
||||
assert_equal '12345', result
|
||||
end
|
||||
|
||||
def test_curly_braces
|
||||
assert_template_result "{}", "{{ '{}' }}"
|
||||
assert_template_result "{}", "{% assign test = '{}' %}{{ test }}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -95,4 +95,21 @@ class VariableTest < Minitest::Test
|
||||
def test_render_symbol
|
||||
assert_template_result 'bar', '{{ foo }}', 'foo' => :bar
|
||||
end
|
||||
|
||||
def test_quoted_single_curly_braces
|
||||
assert_template_result "{user}", "{{ variable | prepend: '{' | append: '}' }}", 'variable' => 'user'
|
||||
end
|
||||
|
||||
def test_string_with_curly_brackets
|
||||
json = '{ "key": { "nested": "value" }}'
|
||||
assert_template_result(json, "{{ '#{json}' }}")
|
||||
end
|
||||
|
||||
def test_liquid_issue_344
|
||||
assert_template_result "blah xx yy }}", "{{ 'blah {{ yy }}' | replace: '{{', 'xx' }}"
|
||||
end
|
||||
|
||||
def test_liquid_issue_213
|
||||
assert_template_result "blah", "{{ 'blah}' | remove: '}' }}"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -82,7 +82,7 @@ class StaticRegistersUnitTest < Minitest::Test
|
||||
static_register["two"] = 4
|
||||
static_register[true] = "foo"
|
||||
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static_registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
||||
assert_equal({ nil => false, "two" => 4, true => "foo" }, static_register.registers)
|
||||
|
||||
static_register
|
||||
@@ -109,7 +109,7 @@ class StaticRegistersUnitTest < Minitest::Test
|
||||
assert_nil static_register.delete(:one)
|
||||
|
||||
assert_equal({}, static_register.registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static_registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
||||
end
|
||||
|
||||
def test_fetch_with_static
|
||||
@@ -135,10 +135,10 @@ class StaticRegistersUnitTest < Minitest::Test
|
||||
assert_equal true, static_register.key?(true)
|
||||
end
|
||||
|
||||
def test_static_register_frozen
|
||||
def test_static_register_can_be_frozen
|
||||
static_register = set_with_static
|
||||
|
||||
static = static_register.static_registers
|
||||
static = static_register.static.freeze
|
||||
|
||||
assert_raises(RuntimeError) do
|
||||
static["two"] = "foo"
|
||||
@@ -176,9 +176,9 @@ class StaticRegistersUnitTest < Minitest::Test
|
||||
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
|
||||
assert_equal({ "one" => 4, "two" => 5, "three" => 6 }, new_register.registers)
|
||||
assert_equal({ "one" => 7, "two" => 8, "three" => 9 }, newest_register.registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static_registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, new_register.static_registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, newest_register.static_registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, new_register.static)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, newest_register.static)
|
||||
end
|
||||
|
||||
def test_multiple_instances_are_unique
|
||||
@@ -204,8 +204,45 @@ class StaticRegistersUnitTest < Minitest::Test
|
||||
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
|
||||
assert_equal({ "one" => 4, "two" => 5, "three" => 6 }, new_register.registers)
|
||||
assert_equal({ "one" => 7, "two" => 8, "three" => 9 }, newest_register.registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static_registers)
|
||||
assert_equal({ foo: :bar }, new_register.static_registers)
|
||||
assert_equal({ bar: :foo }, newest_register.static_registers)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
||||
assert_equal({ foo: :bar }, new_register.static)
|
||||
assert_equal({ bar: :foo }, newest_register.static)
|
||||
end
|
||||
|
||||
def test_can_update_static_directly_and_updates_all_instances
|
||||
static_register = StaticRegisters.new(nil => true, 1 => :one, :one => "one", "two" => 3, false => nil)
|
||||
static_register["one"] = 1
|
||||
static_register["two"] = 2
|
||||
static_register["three"] = 3
|
||||
|
||||
new_register = StaticRegisters.new(static_register)
|
||||
assert_equal({}, new_register.registers)
|
||||
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil }, static_register.static)
|
||||
|
||||
new_register["one"] = 4
|
||||
new_register["two"] = 5
|
||||
new_register["three"] = 6
|
||||
new_register.static["four"] = 10
|
||||
|
||||
newest_register = StaticRegisters.new(new_register)
|
||||
assert_equal({}, newest_register.registers)
|
||||
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 10 }, new_register.static)
|
||||
|
||||
newest_register["one"] = 7
|
||||
newest_register["two"] = 8
|
||||
newest_register["three"] = 9
|
||||
new_register.static["four"] = 5
|
||||
new_register.static["five"] = 15
|
||||
|
||||
assert_equal({ "one" => 1, "two" => 2, "three" => 3 }, static_register.registers)
|
||||
assert_equal({ "one" => 4, "two" => 5, "three" => 6 }, new_register.registers)
|
||||
assert_equal({ "one" => 7, "two" => 8, "three" => 9 }, newest_register.registers)
|
||||
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 5, "five" => 15 }, newest_register.static)
|
||||
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 5, "five" => 15 }, static_register.static)
|
||||
assert_equal({ nil => true, 1 => :one, :one => "one", "two" => 3, false => nil, "four" => 5, "five" => 15 }, new_register.static)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -30,6 +30,67 @@ class TokenizerTest < Minitest::Test
|
||||
assert_equal [1, 1, 3], tokenize_line_numbers(" {{\n funk \n}} ")
|
||||
end
|
||||
|
||||
def test_tokenize_quirks
|
||||
assert_equal ['{%comment%}'], tokenize('{%comment%}')
|
||||
assert_equal [' ', '{%comment%}', ' '], tokenize(' {%comment%} ')
|
||||
|
||||
assert_equal [' ', '{%comment%}', ' ', '{%endcomment%}', ' '], tokenize(' {%comment%} {%endcomment%} ')
|
||||
assert_equal [' ', '{% "{% comment" %}', ' ', '{% endcomment %}', ' '], tokenize(' {% "{% comment" %} {% endcomment %} ')
|
||||
assert_equal [' ', '{% "{% comment %}" %}', ' ', '{% endcomment %}', ' '], tokenize(' {% "{% comment %}" %} {% endcomment %} ')
|
||||
assert_equal [' ', '{% "comment %}" %}', ' ', '{% endcomment %}', ' '], tokenize(' {% "comment %}" %} {% endcomment %} ')
|
||||
assert_equal [' ', '{% "{{ comment" %}', ' ', '{% endcomment %}', ' '], tokenize(' {% "{{ comment" %} {% endcomment %} ')
|
||||
assert_equal [' ', '{% "{{ comment }}" %}', ' ', '{% endcomment %}', ' '], tokenize(' {% "{{ comment }}" %} {% endcomment %} ')
|
||||
assert_equal [' ', '{% "comment }}" %}', ' ', '{% endcomment %}', ' '], tokenize(' {% "comment }}" %} {% endcomment %} ')
|
||||
assert_equal [' ', '{% "comment }" %}', ' ', '{% endcomment %}', ' '], tokenize(' {% "comment }" %} {% endcomment %} ')
|
||||
|
||||
assert_equal [" ", "{%comment%}", " ", "{%endcomment%}", " "], tokenize(" {%comment%} {%endcomment%} ")
|
||||
assert_equal [" ", "{% '{% comment' %}", " ", "{% endcomment %}", " "], tokenize(" {% '{% comment' %} {% endcomment %} ")
|
||||
assert_equal [" ", "{% '{% comment %}' %}", " ", "{% endcomment %}", " "], tokenize(" {% '{% comment %}' %} {% endcomment %} ")
|
||||
assert_equal [" ", "{% 'comment %}' %}", " ", "{% endcomment %}", " "], tokenize(" {% 'comment %}' %} {% endcomment %} ")
|
||||
assert_equal [" ", "{% '{{ comment' %}", " ", "{% endcomment %}", " "], tokenize(" {% '{{ comment' %} {% endcomment %} ")
|
||||
assert_equal [" ", "{% '{{ comment }}' %}", " ", "{% endcomment %}", " "], tokenize(" {% '{{ comment }}' %} {% endcomment %} ")
|
||||
assert_equal [" ", "{% 'comment }}' %}", " ", "{% endcomment %}", " "], tokenize(" {% 'comment }}' %} {% endcomment %} ")
|
||||
assert_equal [" ", "{% 'comment }' %}", " ", "{% endcomment %}", " "], tokenize(" {% 'comment }' %} {% endcomment %} ")
|
||||
|
||||
assert_equal [' ', '{{comment}}', ' ', '{{endcomment}}', ' '], tokenize(' {{comment}} {{endcomment}} ')
|
||||
assert_equal [' ', '{{ "{{ comment" }}', ' ', '{{ endcomment }}', ' '], tokenize(' {{ "{{ comment" }} {{ endcomment }} ')
|
||||
assert_equal [' ', '{{ "{{ comment }}" }}', ' ', '{{ endcomment }}', ' '], tokenize(' {{ "{{ comment }}" }} {{ endcomment }} ')
|
||||
assert_equal [' ', '{{ "comment }}" }}', ' ', '{{ endcomment }}', ' '], tokenize(' {{ "comment }}" }} {{ endcomment }} ')
|
||||
assert_equal [' ', '{{ "{{ comment" }}', ' ', '{{ endcomment }}', ' '], tokenize(' {{ "{{ comment" }} {{ endcomment }} ')
|
||||
assert_equal [' ', '{{ "{{ comment }}" }}', ' ', '{{ endcomment }}', ' '], tokenize(' {{ "{{ comment }}" }} {{ endcomment }} ')
|
||||
assert_equal [' ', '{{ "comment }}" }}', ' ', '{{ endcomment }}', ' '], tokenize(' {{ "comment }}" }} {{ endcomment }} ')
|
||||
assert_equal [' ', '{{ "comment }" }}', ' ', '{{ endcomment }}', ' '], tokenize(' {{ "comment }" }} {{ endcomment }} ')
|
||||
|
||||
assert_equal [" ", "{{comment}}", " ", "{{endcomment}}", " "], tokenize(" {{comment}} {{endcomment}} ")
|
||||
assert_equal [" ", "{{ '{% comment' }}", " ", "{{ endcomment }}", " "], tokenize(" {{ '{% comment' }} {{ endcomment }} ")
|
||||
assert_equal [" ", "{{ '{% comment }}' }}", " ", "{{ endcomment }}", " "], tokenize(" {{ '{% comment }}' }} {{ endcomment }} ")
|
||||
assert_equal [" ", "{{ 'comment }}' }}", " ", "{{ endcomment }}", " "], tokenize(" {{ 'comment }}' }} {{ endcomment }} ")
|
||||
assert_equal [" ", "{{ '{{ comment' }}", " ", "{{ endcomment }}", " "], tokenize(" {{ '{{ comment' }} {{ endcomment }} ")
|
||||
assert_equal [" ", "{{ '{{ comment }}' }}", " ", "{{ endcomment }}", " "], tokenize(" {{ '{{ comment }}' }} {{ endcomment }} ")
|
||||
assert_equal [" ", "{{ 'comment }}' }}", " ", "{{ endcomment }}", " "], tokenize(" {{ 'comment }}' }} {{ endcomment }} ")
|
||||
assert_equal [" ", "{{ 'comment }' }}", " ", "{{ endcomment }}", " "], tokenize(" {{ 'comment }' }} {{ endcomment }} ")
|
||||
|
||||
assert_equal [' ', '{{comment}', ' ', '{{endcomment}', ' '], tokenize(' {{comment} {{endcomment} ')
|
||||
assert_equal [' ', '{{ "{% comment" }', ' ', '{{ endcomment }', ' '], tokenize(' {{ "{% comment" } {{ endcomment } ')
|
||||
assert_equal [' ', '{{ "{% comment }" }', ' ', '{{ endcomment }', ' '], tokenize(' {{ "{% comment }" } {{ endcomment } ')
|
||||
assert_equal [' ', '{{ "comment }" }', ' ', '{{ endcomment }', ' '], tokenize(' {{ "comment }" } {{ endcomment } ')
|
||||
assert_equal [' ', '{{ "{{ comment" }', ' ', '{{ endcomment }', ' '], tokenize(' {{ "{{ comment" } {{ endcomment } ')
|
||||
assert_equal [' ', '{{ "{{ comment }}" }', ' ', '{{ endcomment }', ' '], tokenize(' {{ "{{ comment }}" } {{ endcomment } ')
|
||||
assert_equal [' ', '{{ "comment }}" }', ' ', '{{ endcomment }', ' '], tokenize(' {{ "comment }}" } {{ endcomment } ')
|
||||
assert_equal [' ', '{{ "comment }" }', ' ', '{{ endcomment }', ' '], tokenize(' {{ "comment }" } {{ endcomment } ')
|
||||
|
||||
assert_equal [" ", "{{comment}", " ", "{{endcomment}", " "], tokenize(" {{comment} {{endcomment} ")
|
||||
assert_equal [" ", "{{ '{{ comment' }", " ", "{{ endcomment }", " "], tokenize(" {{ '{{ comment' } {{ endcomment } ")
|
||||
assert_equal [" ", "{{ '{{ comment }' }", " ", "{{ endcomment }", " "], tokenize(" {{ '{{ comment }' } {{ endcomment } ")
|
||||
assert_equal [" ", "{{ 'comment }' }", " ", "{{ endcomment }", " "], tokenize(" {{ 'comment }' } {{ endcomment } ")
|
||||
assert_equal [" ", "{{ '{{ comment' }", " ", "{{ endcomment }", " "], tokenize(" {{ '{{ comment' } {{ endcomment } ")
|
||||
assert_equal [" ", "{{ '{{ comment }}' }", " ", "{{ endcomment }", " "], tokenize(" {{ '{{ comment }}' } {{ endcomment } ")
|
||||
assert_equal [" ", "{{ 'comment }}' }", " ", "{{ endcomment }", " "], tokenize(" {{ 'comment }}' } {{ endcomment } ")
|
||||
assert_equal [" ", "{{ 'comment }' }", " ", "{{ endcomment }", " "], tokenize(" {{ 'comment }' } {{ endcomment } ")
|
||||
|
||||
assert_equal ['{{funk | replace: "}", \'}}\' }}'], tokenize('{{funk | replace: "}", \'}}\' }}')
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def tokenize(source)
|
||||
|
||||
@@ -156,6 +156,12 @@ class VariableUnitTest < Minitest::Test
|
||||
assert_equal ['b', 'c'], lookup.lookups
|
||||
end
|
||||
|
||||
def test_filters_with_properly_quoted_curlies
|
||||
var = create_variable("hello | replace: \"}\", '}}'")
|
||||
assert_equal VariableLookup.new('hello'), var.name
|
||||
assert_equal [['replace', ['}', '}}']]], var.filters
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_variable(markup, options = {})
|
||||
|
||||
Reference in New Issue
Block a user