slice with a negative start counts from the end. When that start points before the beginning of the string or array, there is nothing to return, and Shopify's Liquid returns nothing. We get the first characters instead.…
slice with a negative start counts from the end. When that start points before the beginning of the string or array, there is nothing to return, and Shopify's Liquid returns nothing. We get the first characters instead. A negative length returns content too. Both show up as stray fragments in our breadcrumb and SKU templates.
{{ "hello" | slice: -10, 2 }}.{{ "Liquid" | slice: 1, -2 }}.{{ "1,2,3,4,5" | split: "," | slice: -10, 2 | join: "," }}.An empty result in all three.
heiqui1,2{{ "hello" | slice: -3, 2 }} gives ll, and {{ "hello" | slice: -5, 2 }} gives he.Adapted from harttle/liquidjs (MIT).
Visible test command
TZ=UTC npx --no-install jest --ci --coverage=falseThe repository’s own tests. Run all tests includes them, and so does every submission.
Repository
slice-out-of-range-start
Changes under src/ are evaluated.