Skip to content

Make whitespace filters Unicode-aware#2083

Open
graygilmore wants to merge 1 commit into
mainfrom
gg-fix-existing-whitespace
Open

Make whitespace filters Unicode-aware#2083
graygilmore wants to merge 1 commit into
mainfrom
gg-fix-existing-whitespace

Conversation

@graygilmore
Copy link
Copy Markdown
Contributor

@graygilmore graygilmore commented May 6, 2026

Previously we were only leveraging Ruby's String#strip to handle the logic in these filters but that only covers ASCII whitespace (docs). When rendering Liquid templates into HTML it would be confusing for these filters to not strip all whitespace.

Additionally, it's helpful when trying to compare two values in, say, a Liquid conditional.

This PR updates the implementation of all of our whitespace related filters (strip, rstrip, lstrip, squish) to first convert all whitespace to " " and then use String#strip (or whatever equivalent) as we were before. This ensures that all unicode whitespaces are being removed instead of a subset.

For squish we're leveraging some optimization work done in Rails: rails/rails#56626

@graygilmore graygilmore force-pushed the gg-fix-existing-whitespace branch 2 times, most recently from a6ea845 to 5244e6d Compare May 12, 2026 18:22
@graygilmore graygilmore marked this pull request as ready for review May 12, 2026 20:04
Previously we were only leveraging Ruby's `String#strip` to handle the
logic in these filters but that only covers ASCII whitespace. When
rendering Liquid templates into HTML it would be confusing for these
filters to not strip *all* whitespace.

Additionally, it's helpful when trying to compare two values in, say, a
Liquid conditional.
@graygilmore graygilmore force-pushed the gg-fix-existing-whitespace branch from 5244e6d to ce0d465 Compare May 12, 2026 20:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant