Bug #1953

empty range in String#tr causes unexpected behavior

Added by Yusuke Endoh about 6 years ago. Updated over 4 years ago.

[ruby-dev:39108]
Status:Closed
Priority:Normal
Assignee:Yukihiro Matsumoto
ruby -v:ruby 1.9.2dev (2009-08-18 trunk 24578) [i686-linux Backport:

Description

=begin
Are these intentional?

"ABC".tr("ABC", "pq-a") #=> "pqq"
"ABC".tr("ABC", "pq-ar") #=> "prr"
"ABC".tr("ABC", "pq-ars") #=> "prs"
"ABC".tr("ABC", "pq-arst") #=> "prs"

I expect that an exception is raised or that "p-a" equals to
"ponmlk...cba" (descending order).

For reference, empty range is rejected in Perl:

$ perl -e '"A" =~ tr/A/q-a/;'
Invalid range "q-a" in transliteration operator at -e line 1.

--
Yusuke ENDOH mame@tsg.ne.jp
=end

History

#1 Updated by Yui NARUSE almost 6 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto

=begin

=end

#2 Updated by Yukihiro Matsumoto almost 6 years ago

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

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

=end

Also available in: Atom PDF