Skip to content

Commit 1cb0236

Browse files
committed
Push a test for the defensive FString copying
See #9145
1 parent 3e36f8d commit 1cb0236

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

core/src/test/java/org/jruby/test/TestRubyString.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,20 @@ public void testSplit() throws RaiseException {
7373
res = str.split(context, pat, 4);
7474
assertEquals(3, res.size());
7575
}
76+
77+
// See https://github.com/jruby/jruby/pull/9145
78+
public void testDefensiveFString() throws Throwable {
79+
byte[] bytes = ByteList.plain("foo9145");
80+
RubyString goodString = newString(context, bytes);
81+
RubyString badString = newString(context, bytes);
82+
ByteList badBytes = badString.getByteList();
83+
84+
RubyString fstring = context.runtime.freezeAndDedupString(badString);
85+
badBytes.set(0, 'b');
86+
87+
// previously returned fstring should not have been modified
88+
assertEquals(goodString, fstring);
89+
assertNotSame(fstring.getByteList(), badBytes);
90+
assertNotSame(fstring.getByteList().unsafeBytes(), badBytes.unsafeBytes());
91+
}
7692
}

0 commit comments

Comments
 (0)