aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--activesupport/CHANGELOG2
-rw-r--r--activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb2
-rw-r--r--activesupport/test/multibyte_chars_test.rb4
3 files changed, 6 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG
index d00be783e1..6366a11237 100644
--- a/activesupport/CHANGELOG
+++ b/activesupport/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Make the utf-handler return the correct value for non-matching regular expressions. Closes #9049 [manfred]
+
* Add ljust, rjust and center to utf8-handler. Closes #9165 [manfred]
* Fix Time#advance bug when trying to advance a year from leap day. Closes #8655 [gbuesing]
diff --git a/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb b/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb
index 6ca043ae21..e4ef98f1b6 100644
--- a/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb
+++ b/activesupport/lib/active_support/multibyte/handlers/utf8_handler.rb
@@ -316,8 +316,8 @@ module ActiveSupport::Multibyte::Handlers #:nodoc:
# Used to translate an offset from bytes to characters, for instance one received from a regular expression match
def translate_offset(str, byte_offset)
- return 0 if str == ''
return nil if byte_offset.nil?
+ return 0 if str == ''
chunk = str[0..byte_offset]
begin
begin
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index d8766af3b8..6e87ea8851 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -81,6 +81,8 @@ class CharsTest < Test::Unit::TestCase
with_kcode('UTF8') do
assert_equal 9, (@s[:utf8].chars =~ /ffi/),
"Regex matching should be unicode aware"
+ assert_nil((''.chars =~ /\d+/),
+ "Non-matching regular expressions should return nil")
end
end
@@ -118,7 +120,7 @@ class CharsTest < Test::Unit::TestCase
def test_passthrough_on_kcode
# The easiest way to check if the passthrough is in place is through #size
- with_kcode('nonce') do
+ with_kcode('none') do
assert_equal 26, @s[:utf8].chars.size
end
with_kcode('UTF8') do