mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #2052 from amatsuda/fullwidth_blank
treat fullwidth whitespace as a blank character
This commit is contained in:
commit
003c6516dc
2 changed files with 6 additions and 2 deletions
|
@ -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 'abstract_unit'
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue