liquid icon indicating copy to clipboard operation
liquid copied to clipboard

Filter `size` counts number of bytes instead of number of characters

Open jamslinger opened this issue 4 months ago • 0 comments

Checklist

  • [x] I have searched the issue list
  • [x] I have tested my example against Shopify Liquid. (This isn't necessary if the actual behavior is a panic, or an error for which IsTemplateError returns false.)

Expected Behavior

Return the number of characters instead of the number of bytes when using the size filter on a string.

Actual Behavior

The current implementation returns the number of bytes when using size on a string.

Detailed Description

Shopify's liquid counts number of characters instead of number of bytes when using the size filter on a string, e.g.:

{{ "Straße" | size }} // -> 6, even though "ß" is encoded as a sequence of two bytes, so `len("Straße") = 7`. 

Possible Solution

Return the rune count instead of the number of bytes when using size on a string.

jamslinger avatar Oct 19 '24 08:10 jamslinger