diff --git a/lib/liquid/block_body.rb b/lib/liquid/block_body.rb index 2921ce88..d8c7e453 100644 --- a/lib/liquid/block_body.rb +++ b/lib/liquid/block_body.rb @@ -37,7 +37,7 @@ module Liquid private def parse_for_liquid_tag(tokenizer, parse_context) while (token = tokenizer.shift) - unless token.empty? || token =~ WhitespaceOrNothing + unless token.empty? || token.match?(WhitespaceOrNothing) unless token =~ LiquidTagToken # line isn't empty but didn't match tag syntax, yield and let the # caller raise a syntax error @@ -150,7 +150,7 @@ module Liquid end parse_context.trim_whitespace = false @nodelist << token - @blank &&= !!(token =~ WhitespaceOrNothing) + @blank &&= token.match?(WhitespaceOrNothing) end parse_context.line_number = tokenizer.line_number end diff --git a/lib/liquid/variable_lookup.rb b/lib/liquid/variable_lookup.rb index 9d5dba68..775b002e 100644 --- a/lib/liquid/variable_lookup.rb +++ b/lib/liquid/variable_lookup.rb @@ -2,8 +2,7 @@ module Liquid class VariableLookup - SQUARE_BRACKETED = /\A\[(.*)\]\z/m - COMMAND_METHODS = ['size', 'first', 'last'].freeze + COMMAND_METHODS = ['size', 'first', 'last'].freeze attr_reader :name, :lookups @@ -15,8 +14,8 @@ module Liquid lookups = markup.scan(VariableParser) name = lookups.shift - if name =~ SQUARE_BRACKETED - name = Expression.parse(Regexp.last_match(1)) + if name&.start_with?('[') && name&.end_with?(']') + name = Expression.parse(name[1..-2]) end @name = name @@ -25,8 +24,8 @@ module Liquid @lookups.each_index do |i| lookup = lookups[i] - if lookup =~ SQUARE_BRACKETED - lookups[i] = Expression.parse(Regexp.last_match(1)) + if lookup&.start_with?('[') && lookup&.end_with?(']') + lookups[i] = Expression.parse(lookup[1..-2]) elsif COMMAND_METHODS.include?(lookup) @command_flags |= 1 << i end