aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib
diff options
context:
space:
mode:
authorXavier Noria <fxn@hashref.com>2013-01-28 13:24:56 -0800
committerXavier Noria <fxn@hashref.com>2013-01-28 13:24:56 -0800
commit30034dfbc4beda97fb182fa9bda317a7c3b6615d (patch)
treefc91a1924869c78c1b0f717e384872aaac4ca914 /activesupport/lib
parent764397f17d4140232c1aa62bc593b3e5f25485e7 (diff)
parentb5245da94a7c7667b57bb2184fa9aa7beb998da6 (diff)
downloadrails-30034dfbc4beda97fb182fa9bda317a7c3b6615d.tar.gz
rails-30034dfbc4beda97fb182fa9bda317a7c3b6615d.tar.bz2
rails-30034dfbc4beda97fb182fa9bda317a7c3b6615d.zip
Merge pull request #8830 from antoinelyset/master
Improve String#squish whitespaces matching
Diffstat (limited to 'activesupport/lib')
-rw-r--r--activesupport/lib/active_support/core_ext/string/filters.rb7
1 files changed, 5 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/core_ext/string/filters.rb b/activesupport/lib/active_support/core_ext/string/filters.rb
index e05447439a..1811f9f861 100644
--- a/activesupport/lib/active_support/core_ext/string/filters.rb
+++ b/activesupport/lib/active_support/core_ext/string/filters.rb
@@ -3,6 +3,8 @@ class String
# the string, and then changing remaining consecutive whitespace
# groups into one space each.
#
+ # Note that it handles both ASCII and Unicode whitespace like mongolian vowel separator (U+180E).
+ #
# %{ Multi-line
# string }.squish # => "Multi-line string"
# " foo bar \n \t boo".squish # => "foo bar boo"
@@ -12,8 +14,9 @@ class String
# Performs a destructive squish. See String#squish.
def squish!
- strip!
- gsub!(/\s+/, ' ')
+ gsub!(/\A[[:space:]]+/, '')
+ gsub!(/[[:space:]]+\Z/, '')
+ gsub!(/[[:space:]]+/, ' ')
self
end