Skip to content

Compatibility gaps with Shopify Liquid: {%- endraw %} throws, escape_once double-escapes entities, numeric filters drop leading digits #995

Open

Description

@trackoor

Three differences from Shopify Liquid (liquid gem 5.14) that the differences page does not mention.

// npm i [email protected]
const { Liquid } = require("liquidjs");
const engine = new Liquid();
const show = (t) => { let out; try { out = engine.parseAndRenderSync(t) } catch (e) { out = "Error: " + e.message } console.log(t, "=>", JSON.stringify(out)) };
show('{% raw %}{{ x }}{%- endraw %}');
show('{%- raw -%}{{ x }}{%- endraw -%}');
show('{{ ""hi" © —" | escape_once }}');
show('{{ "Tom & Jerry  " | escape_once }}');
show('{{ "10px" | plus: 5 }}');
show('{{ "16px" | times: 2 }}');
show('{{ "3 items" | minus: 1 }}');
show('{{ "😀ab" | split: "" | join: "|" }}');

Playground (for the filter cases): https://liquidjs.com/playground.html#e3sgIiZxdW90O2hpJnF1b3Q7ICZjb3B5OyAmIzgyMTI7IiB8IGVzY2FwZV9vbmNlIH19Cnt7ICJUb20gJmFtcDsgSmVycnkgJm5ic3A7IiB8IGVzY2FwZV9vbmNlIH19Cnt7ICIxMHB4IiB8IHBsdXM6IDUgfX0Ke3sgIjE2cHgiIHwgdGltZXM6IDIgfX0Ke3sgIjMgaXRlbXMiIHwgbWludXM6IDEgfX0=,e30=

1. Whitespace control on endraw throws "not closed"

Actual: {% raw %}{{ x }}{%- endraw %} -> Error: raw "{% raw %}{{ x }}{%- endraw %}" not closed, line:1, col:10 (same for {%- raw -%}{{ x }}{%- endraw -%}). {% endraw -%} works; only the {%- form fails.
Expected (Ruby Liquid): {{ x }}. Whitespace control is allowed on every tag, including endraw.

2. escape_once escapes entities other than the five it produces itself

Actual:

{{ ""hi" © —" | escape_once }} => ""hi" © —"
{{ "Tom & Jerry  " | escape_once }}        => "Tom & Jerry  "

Expected (Ruby Liquid): "hi" © — and Tom & Jerry  . Shopify's escape_once leaves any existing &name; or &#digits; alone; liquidjs only recognizes & < > " ', so text escaped by anything else (",  , ©) gets escaped a second time.

3. Math filters turn strings with a numeric prefix into 0

Actual: "10px" | plus: 5 -> 5, "16px" | times: 2 -> 0, "3 items" | minus: 1 -> -1.
Expected (Ruby Liquid, which converts with String#to_i): 15, 32, 2. The same conversion makes "0x10" | plus: 0 give 16 in liquidjs and 0 in Ruby. toNumber uses +value || 0; reading the leading integer/decimal would match Ruby.

4. split: "" splits emoji into lone surrogates (minor)

Actual: {{ "😀ab" | split: "" | join: "|" }} -> "\ud83d|\ude00|a|b" (invalid UTF-16 halves in the output).
Expected (Ruby Liquid): 😀|a|b. truncate and slice already work by code point since #981; split with an empty separator does not.

Version: [email protected], also on master 74428ae (built from source).

Credit: https://ucsbplse.github.io/

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions