aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorManfred Stienstra <manfred@fngtps.com>2008-09-21 17:30:45 +0200
committerManfred Stienstra <manfred@fngtps.com>2008-09-21 17:30:45 +0200
commit85c05b53948a64ab0e246239d18e01d317a74d7d (patch)
tree1c8e0d22c75da35c46a51a0c24a125428fd1a83d /activesupport
parent52f8c04e1e0f2e6610e54b00125179ec9dacbcd5 (diff)
downloadrails-85c05b53948a64ab0e246239d18e01d317a74d7d.tar.gz
rails-85c05b53948a64ab0e246239d18e01d317a74d7d.tar.bz2
rails-85c05b53948a64ab0e246239d18e01d317a74d7d.zip
Add tests for u_unpack to make sure it raises an EncodingError on invalid UTF-8 strings.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/multibyte/chars.rb2
-rw-r--r--activesupport/test/multibyte_chars_test.rb11
2 files changed, 12 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/multibyte/chars.rb b/activesupport/lib/active_support/multibyte/chars.rb
index b3fdcdc650..5184026c63 100644
--- a/activesupport/lib/active_support/multibyte/chars.rb
+++ b/activesupport/lib/active_support/multibyte/chars.rb
@@ -446,7 +446,7 @@ module ActiveSupport #:nodoc:
begin
string.unpack 'U*'
rescue ArgumentError
- raise EncodingError.new('malformed UTF-8 character')
+ raise EncodingError, 'malformed UTF-8 character'
end
end
diff --git a/activesupport/test/multibyte_chars_test.rb b/activesupport/test/multibyte_chars_test.rb
index 2fde4d3e30..8aae66b717 100644
--- a/activesupport/test/multibyte_chars_test.rb
+++ b/activesupport/test/multibyte_chars_test.rb
@@ -82,6 +82,17 @@ class MultibyteCharsTest < Test::Unit::TestCase
assert !@proxy_class.consumes?(BYTE_STRING)
end
+ def test_unpack_utf8_strings
+ assert_equal 4, @proxy_class.u_unpack(UNICODE_STRING).length
+ assert_equal 5, @proxy_class.u_unpack(ASCII_STRING).length
+ end
+
+ def test_unpack_raises_encoding_error_on_broken_strings
+ assert_raises(ActiveSupport::Multibyte::EncodingError) do
+ @proxy_class.u_unpack(BYTE_STRING)
+ end
+ end
+
if RUBY_VERSION < '1.9'
def test_concatenation_should_return_a_proxy_class_instance
assert_equal ActiveSupport::Multibyte.proxy_class, ('a'.mb_chars + 'b').class