Project

General

Profile

Bug #2327

String#upto で beg が非英数の時破壊的変更がその後に影響する

Added by naruse (Yui NARUSE) over 9 years ago. Updated about 8 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.2dev (2009-11-02 trunk 25631) [x86_64-freebsd8.0]
Backport:

Description

=begin
String の場合、upto のブロックパラメータを破壊的に変更することが出来ますが、
非英数の際にこれがその後の挙動に影響を与えることがあります。

irb(main):001:0> "1".upto("9"){|x|print x;x.replace("9")}
123456789=> "1"
irb(main):002:0> "a".upto("z"){|x|print x;x.replace("z")}
abcdefghijklmnopqrstuvwxyz=> "a"
irb(main):003:0> "\u3041".upto("\u3093"){|x|print x;x.replace("\u3093")}
ぁ=> "ん"
irb(main):004:0> s="\u3041";s.upto("\u3093"){|x|print x;x.replace("\u3093")}
ぁ=> "ん"

以上のように、"ぁ"のみで終わってしまったり、戻り値が変わってしまったりします。
=end

Associated revisions

Revision a1fc9cd5
Added by naruse (Yui NARUSE) over 9 years ago

  • string.c (rb_str_upto): make next object before yield its block. fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327

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

Revision 25632
Added by naruse (Yui NARUSE) over 9 years ago

  • string.c (rb_str_upto): make next object before yield its block. fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327

Revision 25632
Added by naruse (Yui NARUSE) over 9 years ago

  • string.c (rb_str_upto): make next object before yield its block. fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327

Revision 25632
Added by naruse (Yui NARUSE) over 9 years ago

  • string.c (rb_str_upto): make next object before yield its block. fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327

Revision 25632
Added by naruse (Yui NARUSE) over 9 years ago

  • string.c (rb_str_upto): make next object before yield its block. fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327

Revision 25632
Added by naruse (Yui NARUSE) over 9 years ago

  • string.c (rb_str_upto): make next object before yield its block. fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327

Revision 25632
Added by naruse (Yui NARUSE) over 9 years ago

  • string.c (rb_str_upto): make next object before yield its block. fix: can modify original begin string of String#upto. [ruby-dev:26384] [ruby-dev:39626] #2327

History

#1

Updated by naruse (Yui NARUSE) over 9 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r25632.
Yui, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.

=end

Also available in: Atom PDF