Permalink
Browse files

JRUBY-4464: [1.9] String#tr! and String#tr_s! crash in some cases

Signed-off-by: Vladimir Sizikov <vsizikov@gmail.com>
  • Loading branch information...
calavera authored and vvs committed Jan 12, 2010
1 parent e748f0d commit 895b65fd6d9896949bd68a3e7d6839917dcdb72d
@@ -1 +0,0 @@
-critical(JRUBY-4464):String#tr_s! does not modify self if from_str is empty
@@ -1,3 +1,2 @@
-critical(JRUBY-4464):String#tr! does not modify self if from_str is empty
fails:String#tr translates chars not in from_string when it starts with a ^
fails:String#tr can replace a 7-bit ASCII character with a multibyte one
@@ -6167,7 +6167,7 @@ private IRubyObject trTrans19(ThreadContext context, IRubyObject src, IRubyObjec
boolean cflag = false;
if (value.getRealSize() > 1) {
if (enc.isAsciiCompatible()) {
- if ((trSrc.buf[trSrc.p] & 0xff) == '^' && trSrc.p + 1 < trSrc.pend) {
+ if (trSrc.buf.length > 0 && (trSrc.buf[trSrc.p] & 0xff) == '^' && trSrc.p + 1 < trSrc.pend) {
cflag = true;
trSrc.p++;
}
View
@@ -10,3 +10,4 @@ test_assignment_1_9
test_regexp_1_9
test_io_1_9
test_jruby_4084
+test_string_1_9
View
@@ -0,0 +1,12 @@
+require 'test/unit'
+
+class TestString19 < Test::Unit::TestCase
+ #JRUBY-4464
+ def test_tr_bang
+ assert_nil 'hello'.tr!('','yb')
+ end
+
+ def test_tr_s_bang
+ assert_nil 'hello'.tr_s!('','yb')
+ end
+end

0 comments on commit 895b65f

Please sign in to comment.