aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2011-07-13 19:04:28 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2011-07-13 19:04:28 -0700
commit003c6516dcffcd846d1f257a16062cea657cbd33 (patch)
tree056755a0470b3e958d2ba25fbab6b3d12005dcde /activesupport/lib/active_support
parent54ab63ee77ea850af301cdc2df425e3b182e0c1e (diff)
parent9c60860322d58e1a2fcd42f1a21ec86ec2caa50b (diff)
downloadrails-003c6516dcffcd846d1f257a16062cea657cbd33.tar.gz
rails-003c6516dcffcd846d1f257a16062cea657cbd33.tar.bz2
rails-003c6516dcffcd846d1f257a16062cea657cbd33.zip
Merge pull request #2052 from amatsuda/fullwidth_blank
treat fullwidth whitespace as a blank character
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/core_ext/object/blank.rb6
1 files changed, 5 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb
index 8221dc4abe..677ec1141d 100644
--- a/activesupport/lib/active_support/core_ext/object/blank.rb
+++ b/activesupport/lib/active_support/core_ext/object/blank.rb
@@ -86,14 +86,18 @@ class Hash
end
class String
+ # 0x3000: fullwidth whitespace
+ NON_WHITESPACE_REGEXP = %r![^\s#{[0x3000].pack("U")}]!
+
# A string is blank if it's empty or contains whitespaces only:
#
# "".blank? # => true
# " ".blank? # => true
+ # " ".blank? # => true
# " something here ".blank? # => false
#
def blank?
- self !~ /\S/
+ self !~ NON_WHITESPACE_REGEXP
end
end