Skip to content

Commit 480efa2

Browse files
committed
Fix for JRUBY-4084: Working with the enumerable methods on arrays containing strings created by splicing can raise a Java Exception
Thanks to RJ Lorimer for the fix!
1 parent 14c9378 commit 480efa2

File tree

4 files changed

+13
-2
lines changed

4 files changed

+13
-2
lines changed

src/org/jruby/RubyString.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -6609,7 +6609,7 @@ private IRubyObject each_charCommon18(ThreadContext context, Block block) {
66096609
ByteList val = value.shallowDup();
66106610
while (p < end) {
66116611
int n = StringSupport.length(enc, bytes, p, end);
6612-
block.yield(context, makeShared19(runtime, val, p, n));
6612+
block.yield(context, makeShared19(runtime, val, p-val.begin, n));
66136613
p += n;
66146614
}
66156615
return this;
@@ -6635,7 +6635,7 @@ private IRubyObject each_charCommon19(ThreadContext context, Block block) {
66356635
ByteList val = value.shallowDup();
66366636
while (p < end) {
66376637
int n = StringSupport.length(enc, bytes, p, end);
6638-
block.yield(context, makeShared19(runtime, val, p, n));
6638+
block.yield(context, makeShared19(runtime, val, p-value.begin, n));
66396639
p += n;
66406640
}
66416641
return this;

test/jruby_index

+1
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ test_java_accessible_object
5555
test_java_extension
5656
test_java_wrapper_deadlock
5757
test_jruby_internals
58+
test_jruby_4084
5859
compiler/test_jrubyc
5960
test_launching_by_shell_script
6061
#test_local_jump_error

test/ruby_1_9_index

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ test_loop_1_9
99
test_assignment_1_9
1010
test_regexp_1_9
1111
test_io_1_9
12+
test_jruby_4084

test/test_jruby_4084.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'test/unit'
2+
3+
class TestJruby4084 < Test::Unit::TestCase
4+
def test_jruby_4084
5+
result = ["1"[0..1], "1111111"[5..6]].map{|i| i.each_char.to_a.map{|i| i == "1"}}
6+
assert_equal [[true], [true, true]], result
7+
end
8+
end
9+

0 commit comments

Comments
 (0)