Skip to content

Conversation

APErebus
Copy link

The Truncate function automatically applies a ... suffix when the supplied string exceeds the specified length. While this is documented appropriately, I think this is poor default behaviour.

It means that you can't truncate a long string and guarantee that the resulting string is the correct length. For instance, #{abcdef | Truncate 3} results in a 6 character long string abc....

The only way to fix this is to then perform a replace... so #{abcdef | Truncate 3 | Replace "..." ""} which seems counter intuitive.

This PR changes the truncate function to remove the default ... suffix, but adds a second parameter to allow for a custom suffix to be specified if required.

e.g. #{abcdef 3 "123"} results in abc123`.

This is a breaking change to the Truncate function, so I'm not sure of the process for this. If we want to maintain the current behaviour but add support for no suffix, we could change it so the 2nd parameter can be "" to set no suffix, but my opinion is that no suffix by default would be desirable behaviour.

tl;dr: if I truncate a string, I expect the result to be equal to or less than the truncate length, not longer.

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