Backport #7954 closed
"あ".byteslice(0,2).valid_encoding? should return false
Added by Tietew (Toru Iwase) almost 12 years ago.
Updated almost 12 years ago.
Description
=begin
valid encodingな文字列に対するString#bytesliceがinvalid encodingなバイト列を生成してもvalid_encoding?がtrueになります。
これはfalseになるべきだと思います。
なお、1.9.3も同じ挙動です。
irb(main):001:0> RUBY_DESCRIPTION
=> "ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-linux]"
irb(main):002:0> "あ".encoding
=> #Encoding:UTF-8
irb(main):003:0> "あ".valid_encoding?
=> true
irb(main):004:0> "あ".byteslice(0,2)
=> "\xE3\x81"
irb(main):005:0> "あ".byteslice(0,2).valid_encoding?
=> true
irb(main):006:0> "\xE3\x81".encoding
=> #Encoding:UTF-8
irb(main):007:0> "\xE3\x81".valid_encoding?
=> false
ちなみに、invalidな文字列を正しい位置でbytesliceすると正しくvalidと判定されます。
irb(main):025:0> "あ\xE3".valid_encoding?
=> false
irb(main):026:0> "あ\xE3".byteslice(0,3).valid_encoding?
=> true
=end
この場合の問題はそもぞも
"あ".byteslice(0,2).encoding
=> #Encoding:UTF-8
にあるかと思います。byteslice の戻り値の encoding は BINARY にすべきだと思います。
Category set to M17N
Status changed from Open to Assigned
Assignee set to naruse (Yui NARUSE)
duerst (Martin Dürst) wrote:
この場合の問題はそもぞも
"あ".byteslice(0,2).encoding
=> #Encoding:UTF-8
にあるかと思います。byteslice の戻り値の encoding は BINARY にすべきだと思います。
BINARY で受け取りたいならば、"あ".b.slice(0,2) とすればいいのであって、別のメソッドである意味がありません。
Status changed from Assigned to Closed
% Done changed from 0 to 100
This issue was solved with changeset r39495.
Toru, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
Tracker changed from Bug to Backport
Project changed from Ruby master to Backport200
Category deleted (M17N )
Status changed from Closed to Assigned
Assignee changed from naruse (Yui NARUSE) to nagachika (Tomoyuki Chikanaga)
Target version deleted (2.0.0 )
Status changed from Assigned to Closed
This issue was solved with changeset r39706.
Toru, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 39495: [Backport #7954 ]
* string.c (str_byte_substr): don't set coderange if it's not known.
[Bug #7954] [ruby-dev:47108]
Project changed from Backport200 to Backport193
Status changed from Closed to Assigned
Assignee changed from nagachika (Tomoyuki Chikanaga) to usa (Usaku NAKAMURA)
1.9.3 でも同じ挙動ということなので Backport93 に移動しておきます。
Status changed from Assigned to Closed
This issue was solved with changeset r39978.
Toru, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
merge revision(s) 39495: [Backport #7954 ]
* string.c (str_byte_substr): don't set coderange if it's not known.
[Bug #7954] [ruby-dev:47108]
Also available in: Atom
PDF
Like 0
Like 0 Like 0 Like 0 Like 0 Like 0 Like 0 Like 0