Shopify / liquid

Liquid markup language. Safe, customer facing template language for flexible web apps.
https://shopify.github.io/liquid/
MIT License
11.05k stars 1.38k forks source link

[Question] Is the square bracket special character even if quoted? #1740

Closed koshigoe closed 11 months ago

koshigoe commented 1 year ago

Is there a document that describes Referencing handles in detail?

{{ item['x]'] }}

Is the key not x]? Is this behavior specification or bug?

  1. item['x]']item['key']
  2. item['key']"value"
```ruby require 'liquid' template =<<~LIQUID {{ item['x]'] }} LIQUID puts Liquid::Template.parse(template, error_mode: :strict).render!( { 'x' => 'key', 'item' => { 'key' => 'value', } }, { strict_variables: true }, ) __END__ value ```

{{ shop['shop["id"]'] }}

Fixed bug? When will it be released?

```ruby require 'liquid' template =<<~LIQUID shop["name"] = {{ shop["name"] }} shop["id"] = {{ shop["id"] }} shop[shop["name"]] = {{shop[shop["name"]] }} shop['shop["name"]'] = {{ shop['shop["name"]'] }} shop['[]'] = {{ shop['[]'] }} LIQUID puts Liquid::Template.parse(template, error_mode: :strict).render!( { 'shop' => { 'id' => '53154513094', 'name' => 'id', 'shop["name"]' => 'SHOP', '[]' => '[]', }, nil => 'id', }, { strict_variables: true }, ) __END__ ### master branch (0b9318222bcc09681e52fd5b8e70262274e673bf) shop["name"] = id shop["id"] = 53154513094 shop[shop["name"]] = 53154513094 shop['shop["name"]'] = SHOP shop['[]'] = [] ### 5.4.0 shop["name"] = id shop["id"] = 53154513094 shop[shop["name"]] = 53154513094 shop['shop["name"]'] = 53154513094 shop['[]'] = 53154513094 ```

{{ item["key\""] }}

Not about square bracket. About quote (", ').

The quote character can't use in quoted key? Is the backslash escape not allowed?

```ruby require 'liquid' template =<<~LIQUID {{ item["key\\""] }} LIQUID puts template puts Liquid::Template.parse(template, error_mode: :strict).render!( { 'item' => { 'key"' => 'value', }, }, { strict_variables: true }, ) __END__ lib/liquid/lexer.rb:52:in `tokenize': Liquid syntax error: Unexpected character " in "{{ item["key\""] }}" (Liquid::SyntaxError) ```
koshigoe commented 1 year ago

If there is no specification, I would like to know the correct Liquid implementation. Is liquidjs the correct Liquid implementation?