{"record":{"id":"0f04bd439d066b33","repo":"Shopify/liquid","slug":"bare-bracket-access-is-not-allowed-use-expressi","errorCode":null,"errorMessage":"Bare bracket access is not allowed. Use #{Expression::SELF}['...'] instead","messagePattern":"Bare bracket access is not allowed\\. Use #(.+?)\\['\\.\\.\\.'\\] instead","errorType":"exception","errorClass":"Liquid::SyntaxError","httpStatus":null,"severity":"error","filePath":"lib/liquid/parser.rb","lineNumber":58,"sourceCode":"      @p += 1\n      token[1]\n    end\n\n    def look(type, ahead = 0)\n      tok = @tokens[@p + ahead]\n      return false unless tok\n      tok[0] == type\n    end\n\n    def expression\n      token = @tokens[@p]\n      case token[0]\n      when :id\n        str = consume\n        str << variable_lookups\n      when :open_square\n        if @reject_bare_brackets\n          raise SyntaxError, \"Bare bracket access is not allowed. Use #{Expression::SELF}['...'] instead\"\n        end\n        str = consume.dup\n        str << expression\n        str << consume(:close_square)\n        str << variable_lookups\n      when :string, :number\n        consume\n      when :open_round\n        consume\n        first = expression\n        consume(:dotdot)\n        last = expression\n        consume(:close_round)\n        \"(#{first}..#{last})\"\n      else\n        raise SyntaxError, \"#{token} is not a valid expression\"\n      end\n    end","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/Shopify/liquid/blob/807d45a6b3d4568e64e86b375e3702df2c7c860c/lib/liquid/parser.rb#L40-L76","documentation":"In strict2 parser mode (@reject_bare_brackets), Liquid refuses to parse a bare [ opening square bracket when starting an expression. Developers must write the explicit self reference Expression::SELF ('this') before bracket access, e.g. this['key'], because a bare bracket is ambiguous in strict mode.","triggerScenarios":"Parsing a template expression that begins with [ ... ] (e.g. {{ ['key'] }} or tag markup like {% for item in ['a','b'] %}) while the parser was constructed with reject_bare_brackets: true (strict2).","commonSituations":"Upgrading to Shopify Liquid versions that enable strict bracket rules; themes/linters enforcing strict2; code that relied on shorthand bracket variable access.","solutions":["Prefix bracket access with the self expression: replace ['key'] with this['key']","Wrap dynamic keys in a variable and access via dot or bracketed self access","Use the non-strict parser if the legacy syntax must be preserved"],"exampleFix":"<!-- before -->\n{% assign x = ['a', 'b'] %}\n<!-- after -->\n{% assign x = this['a', 'b'] %} or use this[0]['a'] style access","handlingStrategy":"validation","validationCode":"def bare_bracket_free?(tpl)\n  !tpl.match?(/\\{\\{\\s*\\[/) && !tpl.match?(/\\{%[^%]*\\s\\[/)\nend","typeGuard":null,"tryCatchPattern":"begin\n  Liquid::Template.parse(tpl)\nrescue Liquid::SyntaxError => e\n  raise unless e.message.include?('Bare bracket access')\n  # auto-fix or surface guidance to use this['...']\nend","preventionTips":["Use this['key'] instead of bare ['key'] for bracket access","Enable strict parsing in dev to catch this early","Document strict2 syntax rules for theme authors"],"tags":["liquid","template-engine","syntax-error","strict-mode"],"backgroundTag":"invalid-syntax","analyzedSha":"807d45a6b3d4568e64e86b375e3702df2c7c860c","analyzedAt":"2026-09-08T11:31:38.917Z","contentChangedAt":"2026-09-08T11:31:38.917Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}