From 9c60860322d58e1a2fcd42f1a21ec86ec2caa50b Mon Sep 17 00:00:00 2001 From: Akira Matsuda Date: Wed, 13 Jul 2011 20:30:34 +0900 Subject: treat fullwidth whitespace as a blank character --- activesupport/lib/active_support/core_ext/object/blank.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'activesupport/lib/active_support/core_ext/object/blank.rb') 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 -- cgit v1.2.3