From 7d2a9da8bc0712117c082c5d3e07356f35522feb Mon Sep 17 00:00:00 2001 From: Dylan Thacker-Smith Date: Thu, 17 Nov 2022 09:50:12 -0500 Subject: [PATCH] Preserve separator at start of variable from QuotedFragment skipped chars --- lib/liquid/variable.rb | 4 +++- test/unit/migrate_unit_test.rb | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/liquid/variable.rb b/lib/liquid/variable.rb index a1b06ea9..ddda63b1 100644 --- a/lib/liquid/variable.rb +++ b/lib/liquid/variable.rb @@ -100,7 +100,9 @@ module Liquid new_filter_markup = Utils.match_captures_replace(filters_match, 1 => new_filters_markup) end - Utils.match_captures_replace(markup_match, 1 => new_name_markup, 2 => new_filter_markup) + new_markup = Utils.match_captures_replace(markup_match, 1 => new_name_markup, 2 => new_filter_markup) + new_markup.prepend(" ") if markup_match.begin(0) > 0 + new_markup end def self.lax_migrate_filter_argument(unparsed_arg) diff --git a/test/unit/migrate_unit_test.rb b/test/unit/migrate_unit_test.rb index e9292c02..e1006323 100644 --- a/test/unit/migrate_unit_test.rb +++ b/test/unit/migrate_unit_test.rb @@ -29,7 +29,8 @@ class MigrateUnitTest < Minitest::Test with_error_mode(:lax) do assert_migration({ %({{ ,|"' }}) => "{{ }}", # no MarkupWithQuotedFragment match, skipping characters - %({{ ,|"' 123 }}) => "{{ 123 }}", # MarkupWithQuotedFragment skipped characters + %({{ ,|"' 123 }}) => "{{ 123 }}", # MarkupWithQuotedFragment skipped characters + "{{,-2}}" => "{{ -2}}", # preserve separators when removing ignored characters "{{ 12 34 }}" => "{{ 12 }}", # no FilterMarkupRegex match, skipping characters "{{ -12 34 | abs }}" => "{{ -12 | abs }}", # FilterMarkupRegex skipped characters %({{ -12 | '" abs }}) => "{{ -12 | abs }}", # FilterParser skipped characters