# \[Bug #1953\] empty range in String#tr causes unexpected behavior

**URL:** <https://www.ruby-forum.com/t/bug-1953-empty-range-in-string-tr-causes-unexpected-behavior/173948>\
**Category:** Development\
**Created:** [August 18, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/bug-1953-empty-range-in-string-tr-causes-unexpected-behavior/173948 "2009-08-18T17:17:53Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yusuke\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f08c70/32.png) [@Yusuke\_E](https://www.ruby-forum.com/u/Yusuke_E)\
**Post date:** [August 18, 2009, 5:17pm UTC](https://www.ruby-forum.com/t/bug-1953-empty-range-in-string-tr-causes-unexpected-behavior/173948/1 "2009-08-18T17:17:53Z")

</div>

Bug #1953: empty range in String#tr causes unexpected behavior  
[http://redmine.ruby-lang.org/issues/show/1953](http://redmine.ruby-lang.org/issues/show/1953)

e$B5/I\<\<Te(B: Yusuke E.  
e$B%9%F!\<%?%9e(B: Open, e$BM%@hEYe(B: Normal  
Target version: 1.9.x  
ruby -v: ruby 1.9.2dev (2009-08-18 trunk 24578) [i686-linux

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 [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![Yusuke\_E](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/y/f08c70/32.png) [@Yusuke\_E](https://www.ruby-forum.com/u/Yusuke_E)\
**Post date:** [October 30, 2009, 11:14am UTC](https://www.ruby-forum.com/t/bug-1953-empty-range-in-string-tr-causes-unexpected-behavior/173948/2 "2009-10-30T11:14:55Z")

</div>

e$B%A%1%C%He(B #1953 e$B$,99?7$5$l$^$7$?!#e(B (by Yukihiro M.)

e$B%9%F!\<%?%9e(B Assignede$B$+$ie(BClosede$B$KJQ99e(B  
e$B?JD=e(B % 0e$B$+$ie(B100e$B$KJQ99e(B

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.

* * *

[http://redmine.ruby-lang.org/issues/show/1953](http://redmine.ruby-lang.org/issues/show/1953)
