From db30e7bb96265861a8e65d6faff724f4e3d27c3f Mon Sep 17 00:00:00 2001 From: duerst Date: Thu, 2 Jun 2016 01:24:52 +0000 Subject: * string.c: Raise ArgumentError when invalid string is detected in case mapping methods. * enc/unicode.c: Check for invalid string and signal with negative length value. * test/ruby/enc/test_case_mapping.rb: Add tests for above. * test/ruby/test_m17n_comb.rb: Add a message to clarify test failure. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/enc/test_case_mapping.rb | 7 +++++++ test/ruby/test_m17n_comb.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'test') diff --git a/test/ruby/enc/test_case_mapping.rb b/test/ruby/enc/test_case_mapping.rb index 2ef3360314..ac86729886 100644 --- a/test/ruby/enc/test_case_mapping.rb +++ b/test/ruby/enc/test_case_mapping.rb @@ -60,6 +60,13 @@ class TestCaseMappingPreliminary < Test::Unit::TestCase check_swapcase_properties 'yUKIHIRO matsumoto (MAtz)', 'Yukihiro MATSUMOTO (maTZ)', :lithuanian end + def test_invalid + assert_raise(ArgumentError, "Should not be possible to upcase invalid string.") { "\xEB".force_encoding('UTF-8').upcase } + assert_raise(ArgumentError, "Should not be possible to downcase invalid string.") { "\xEB".force_encoding('UTF-8').downcase } + assert_raise(ArgumentError, "Should not be possible to capitalize invalid string.") { "\xEB".force_encoding('UTF-8').capitalize } + assert_raise(ArgumentError, "Should not be possible to swapcase invalid string.") { "\xEB".force_encoding('UTF-8').swapcase } + end + def test_general check_downcase_properties 'résumé dürst ĭñŧėřŋãţijňőńæłĩżàťïōņ', 'RÉSUMÉ DÜRST ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤÏŌŅ', :lithuanian check_upcase_properties 'RÉSUMÉ DÜRST ĬÑŦĖŘŊÃŢIJŇŐŃÆŁĨŻÀŤÏŌŅ', 'résumé dürst ĭñŧėřŋãţijňőńæłĩżàťïōņ', :lithuanian diff --git a/test/ruby/test_m17n_comb.rb b/test/ruby/test_m17n_comb.rb index 054287e2b5..99c162a92f 100644 --- a/test/ruby/test_m17n_comb.rb +++ b/test/ruby/test_m17n_comb.rb @@ -808,7 +808,7 @@ class TestM17NComb < Test::Unit::TestCase def test_str_downcase STRINGS.each {|s| if !s.valid_encoding? - assert_raise(ArgumentError) { s.downcase } + assert_raise(ArgumentError, "Offending string: #{s.inspect}, encoding: #{s.encoding}") { s.downcase } next end t = s.downcase -- cgit v1.2.3