From 2a8b75ba5bec1fd6210ac64c92f0a3c9bccde3a0 Mon Sep 17 00:00:00 2001 From: Michael Go Date: Thu, 14 Nov 2024 00:59:01 -0400 Subject: [PATCH] fix quirky negative sign expression markup parsing --- lib/liquid.rb | 2 +- lib/liquid/expression.rb | 3 ++- test/integration/expression_test.rb | 14 +++++++++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/liquid.rb b/lib/liquid.rb index 0a970005d..367fc3c43 100644 --- a/lib/liquid.rb +++ b/lib/liquid.rb @@ -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' @@ -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' diff --git a/lib/liquid/expression.rb b/lib/liquid/expression.rb index 22cc7227e..e10f97939 100644 --- a/lib/liquid/expression.rb +++ b/lib/liquid/expression.rb @@ -57,7 +57,8 @@ class Expression2 'true' => true, 'false' => false, 'blank' => '', - 'empty' => '' + 'empty' => '', + '-' => VariableLookup.parse("-") }.freeze DOT = ".".ord diff --git a/test/integration/expression_test.rb b/test/integration/expression_test.rb index 7f451afd1..dc57ad286 100644 --- a/test/integration/expression_test.rb +++ b/test/integration/expression_test.rb @@ -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 @@ -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)