Quote non-strictly valid identifiers in variable lookups

This commit is contained in:
Dylan Thacker-Smith
2022-11-17 09:51:23 -05:00
parent 7d2a9da8bc
commit 106ca1bd69
2 changed files with 10 additions and 8 deletions
+5 -3
View File
@@ -20,12 +20,14 @@ module Liquid
markup.scan(VariableParser) do |lookup|
last_match = Regexp.last_match
first_match ||= last_match
new_markup ||= +""
if lookup&.start_with?('[') && lookup&.end_with?(']')
new_markup ||= +""
new_markup << "[" << Expression.lax_migrate(lookup[1..-2]) << "]"
elsif !lookup.match?(/\A#{Liquid::Lexer::IDENTIFIER}\z/)
# quote non-strictly valid identifiers
new_markup << "['" << lookup << "']"
else
new_markup << "." if new_markup
new_markup ||= +""
new_markup << "." unless new_markup.empty?
new_markup << lookup
end
end