Project

General

Profile

Backport #7954

"あ".byteslice(0,2).valid_encoding? should return false

Added by Tietew (Toru Iwase) over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
[ruby-dev:47108]

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

Associated revisions

Revision 2d3808ee
Added by naruse (Yui NARUSE) over 6 years ago

  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39495 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 39495
Added by naruse (Yui NARUSE) over 6 years ago

  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]

Revision 39495
Added by naruse (Yui NARUSE) over 6 years ago

  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]

Revision 39495
Added by naruse (Yui NARUSE) over 6 years ago

  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]

Revision 39495
Added by naruse (Yui NARUSE) over 6 years ago

  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]

Revision 39495
Added by naruse (Yui NARUSE) over 6 years ago

  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]

Revision 39495
Added by naruse (Yui NARUSE) over 6 years ago

  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]

Revision d2b2159f
Added by nagachika (Tomoyuki Chikanaga) over 6 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@39706 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision d8bb5917
Added by usa (Usaku NAKAMURA) over 6 years ago

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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@39978 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 39978
Added by usa (Usaku NAKAMURA) over 6 years ago

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]

History

Updated by duerst (Martin Dürst) over 6 years ago

この場合の問題はそもぞも

"あ".byteslice(0,2).encoding
=> #Encoding:UTF-8

にあるかと思います。byteslice の戻り値の encoding は BINARY にすべきだと思います。

Updated by naruse (Yui NARUSE) over 6 years ago

  • 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) とすればいいのであって、別のメソッドである意味がありません。

#3

Updated by naruse (Yui NARUSE) over 6 years ago

  • 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.


  • string.c (str_byte_substr): don't set coderange if it's not known. [Bug #7954] [ruby-dev:47108]
#4

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • 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)
#5

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • 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]
#6

Updated by nagachika (Tomoyuki Chikanaga) over 6 years ago

  • 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 に移動しておきます。

#7

Updated by usa (Usaku NAKAMURA) over 6 years ago

  • 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