String#squish replaces all whitespaces with spaces
The documentation for String#squish states that it "Strips leading and trailing whitespace and squashes internal whitespace." It fails to mention that all occurences in the string that match \s (which expands to /[ \t\r\n\f]/, that is: space, tab, carriage return, newline and form feed) are replace by a whitespace. I would have excpected it to at least leave a single \n alone.
It would be nice to update the documentation to reflect the rather unexcpected string modification.
I guess we can add an option to keep \r\n untouched. How does this sound?
Hey, thanks for your fast response.
I think my issue is more with fact that all whitespace characters are replaced with spaces. I think the most important thing is to update the documentation to reflect the actual behaviour. I would not add a special option just for \n\r, because a similar case could probably made for the other characters as well. Maybe an option to either:
- Leave single whitespace characters alone (
/\s{2,}/), or - to only affect space characters.
I'm not really sold on either of the two options, just brainstorming.
Thank you again for your fast response and the great library :)