diff options
author | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-02 01:24:52 +0000 |
---|---|---|
committer | duerst <duerst@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-06-02 01:24:52 +0000 |
commit | 3dd98b2446271f8ad2837bc4b63c459c131c579f (patch) | |
tree | afcc1e9b300fbe31a1b078c067ea5b85f01b2382 /enc/unicode.c | |
parent | 2fe605911ce3b6677b160afac90b554ba69e6bf1 (diff) | |
download | ruby-3dd98b2446271f8ad2837bc4b63c459c131c579f.tar.gz |
* 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
Diffstat (limited to 'enc/unicode.c')
-rw-r--r-- | enc/unicode.c | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/enc/unicode.c b/enc/unicode.c index 5a9aea0fa7..39d1e7a31f 100644 --- a/enc/unicode.c +++ b/enc/unicode.c @@ -669,14 +669,20 @@ onigenc_unicode_case_map(OnigCaseFoldType* flagP, OnigCodePoint code; OnigUChar *to_start = to; OnigCaseFoldType flags = *flagP; + int codepoint_length; + to_end -= CASE_MAPPING_SLACK; /* copy flags ONIGENC_CASE_UPCASE and ONIGENC_CASE_DOWNCASE over to * ONIGENC_CASE_UP_SPECIAL and ONIGENC_CASE_DOWN_SPECIAL */ flags |= (flags&(ONIGENC_CASE_UPCASE|ONIGENC_CASE_DOWNCASE))<<ONIGENC_CASE_SPECIAL_OFFSET; while (*pp<end && to<=to_end) { + codepoint_length = ONIGENC_PRECISE_MBC_ENC_LEN(enc, *pp, end); + if (codepoint_length < 0) + return codepoint_length; /* encoding invalid */ code = ONIGENC_MBC_TO_CODE(enc, *pp, end); - *pp += enclen(enc, *pp, end); + *pp += codepoint_length; + if (code<='z') { /* ASCII comes first */ if (code>='a' && code<='z') { if (flags&ONIGENC_CASE_UPCASE) { |