提交 9c608603 编写于 作者: A Akira Matsuda

treat fullwidth whitespace as a blank character

上级 704ee0df
......@@ -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
......
......@@ -2,7 +2,7 @@
require 'active_support/core_ext/object/blank'
class BlankTest < Test::Unit::TestCase
BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", [], {} ]
BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", ' ', [], {} ]
NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ]
def test_blank
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册