Skip to content

Commit

Permalink
fix quirky negative sign expression markup parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
ggmichaelgo committed Nov 14, 2024
1 parent c6d502e commit 2a8b75b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/liquid.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ module Liquid
require 'liquid/errors'
require 'liquid/interrupts'
require 'liquid/strainer_template'
require 'liquid/expression'
require 'liquid/context'
require 'liquid/tag'
require 'liquid/block_body'
Expand All @@ -77,6 +76,7 @@ module Liquid
require 'liquid/variable_lookup'
require 'liquid/range_lookup'
require 'liquid/resource_limits'
require 'liquid/expression'
require 'liquid/template'
require 'liquid/condition'
require 'liquid/utils'
Expand Down
3 changes: 2 additions & 1 deletion lib/liquid/expression.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ class Expression2
'true' => true,
'false' => false,
'blank' => '',
'empty' => ''
'empty' => '',
'-' => VariableLookup.parse("-")
}.freeze

DOT = ".".ord
Expand Down
14 changes: 13 additions & 1 deletion test/integration/expression_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_int
end

def test_float
assert_template_result("-17.42", "{{ -17.42 }}")
assert_template_result("-17.42", "{{ -17.42 }}")
assert_template_result("2.5", "{{ 2.5 }}")
assert_expression_result(1.5, "1.5")
end
Expand All @@ -42,6 +42,18 @@ def test_range
)
end

def test_quirky_negative_sign_expression_markup
result = Expression.parse("-")
assert(result.is_a?(VariableLookup))
assert_equal("-", result.name)

# for this template, the expression markup is "-"
assert_template_result(
"",
"{{ - 'theme.css' - }}",
)
end

private

def assert_expression_result(expect, markup, **assigns)
Expand Down

0 comments on commit 2a8b75b

Please sign in to comment.