Actions
Bug #10078
closedString#count() returns wrong count under specific conditions
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.0.0p481 (2014-05-08) [i386-mingw32]
Backport:
Description
以下の条件の場合、String#countが誤った文字数を返します。
- 文字コードがWindows-31J (文字コード体系が違うせいか、UTF_8, ISO2022_JP, EUC_JPでは再現せず)
- countの引数が1バイト文字一つのみ
- Stringにcountに指定された文字と一致する文字コードが含まれる。
異常な例: 和は0x9861, aは0x61
>ruby -ve "puts 'a-和'.count('a')"
ruby 2.0.0p481 (2014-05-08) [i386-mingw32]
2
正常な例: countに2バイト以上与えると動作が正しくなります。
'a-a'などtr由来のcountの動作も的確ですが、'a-a'と'a'は等価なはずなのに異常な例と結果が異なります。
>ruby -ve "puts 'a-和'.count('a-a')"
ruby 2.0.0p481 (2014-05-08) [i386-mingw32]
1
>ruby -ve "puts 'a-和'.count('ab')"
ruby 2.0.0p481 (2014-05-08) [i386-mingw32]
1
Updated by nobu (Nobuyoshi Nakada) over 10 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
Applied in changeset r46896.
string.c: fix wrong single-byte optimization
- string.c (rb_str_count): fix wrong single-byte optimization.
7bit ascii can be a trailing byte in Shift_JIS.
[ruby-dev:48442] [Bug #10078]
Updated by nagachika (Tomoyuki Chikanaga) over 10 years ago
- Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED
Updated by nagachika (Tomoyuki Chikanaga) about 10 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE
Backported into ruby_2_1
branch at r47255.
Updated by usa (Usaku NAKAMURA) about 10 years ago
- Backport changed from 2.0.0: REQUIRED, 2.1: DONE to 2.0.0: DONE, 2.1: DONE
backported into ruby_2_0_0
at r47401.
Actions
Like0
Like0Like0Like0Like0