From cea4187627cd1c907b0863dc1cdff5a74508fda3 Mon Sep 17 00:00:00 2001 From: Scott Andreas Date: Mon, 13 Jul 2009 23:43:58 -0700 Subject: [PATCH] Test and accompanying patch for an issue in which an ArgumentError is raised when .blank? is called on a UTF-8 string for which .valid_encoding? == false in Ruby 1.9.1. See Lighthouse #2628 for details. --- .../lib/active_support/core_ext/object/blank.rb | 2 +- activesupport/test/core_ext/blank_test.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/object/blank.rb b/activesupport/lib/active_support/core_ext/object/blank.rb index 9a1f663..274af90 100644 --- a/activesupport/lib/active_support/core_ext/object/blank.rb +++ b/activesupport/lib/active_support/core_ext/object/blank.rb @@ -47,7 +47,7 @@ end class String #:nodoc: def blank? - self !~ /\S/ + (!self.respond_to?(:valid_encoding?) or self.valid_encoding?) ? self !~ /\S/ : self.strip.size == 0 end end diff --git a/activesupport/test/core_ext/blank_test.rb b/activesupport/test/core_ext/blank_test.rb index 1dbbf3f..5c0edde 100644 --- a/activesupport/test/core_ext/blank_test.rb +++ b/activesupport/test/core_ext/blank_test.rb @@ -11,7 +11,8 @@ end class BlankTest < Test::Unit::TestCase BLANK = [ EmptyTrue.new, nil, false, '', ' ', " \n\t \r ", [], {} ] - NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 } ] + NOT = [ EmptyFalse.new, Object.new, true, 0, 1, 'a', [nil], { nil => 0 }, "Coeur D\xD5Alene" ] + NOT.last.force_encoding(Encoding::UTF_8) if RUBY_VERSION >= '1.9' def test_blank BLANK.each { |v| assert v.blank?, "#{v.inspect} should be blank" } -- 1.5.3.1