提交 85c05b53 编写于 作者: M Manfred Stienstra

Add tests for u_unpack to make sure it raises an EncodingError on invalid UTF-8 strings.

上级 52f8c04e
......@@ -446,7 +446,7 @@ def u_unpack(string)
begin
string.unpack 'U*'
rescue ArgumentError
raise EncodingError.new('malformed UTF-8 character')
raise EncodingError, 'malformed UTF-8 character'
end
end
......
......@@ -82,6 +82,17 @@ def test_consumes_utf8_strings
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册