Make whitespace filters Unicode-aware#2083
Open
graygilmore wants to merge 1 commit into
Open
Conversation
a6ea845 to
5244e6d
Compare
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.
5244e6d to
ce0d465
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Previously we were only leveraging Ruby's
String#stripto 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 useString#strip(or whatever equivalent) as we were before. This ensures that all unicode whitespaces are being removed instead of a subset.For
squishwe're leveraging some optimization work done in Rails: rails/rails#56626