Skip to content

Commit 476962b

Browse files
committed
Make new appendStringUnsafe to see how latest change to appendString plays out
1 parent bbcad68 commit 476962b

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

core/src/main/java/org/jruby/RubyProc.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -239,17 +239,17 @@ public IRubyObject to_s() {
239239
string.setEncoding(RubyString.ASCII);
240240

241241
string.append(types(runtime, type()));
242-
string.catString(":0x" + Integer.toString(System.identityHashCode(block), 16));
242+
string.catStringUnsafe(":0x" + Integer.toString(System.identityHashCode(block), 16));
243243

244244
boolean isSymbolProc = block.getBody() instanceof RubySymbol.SymbolProcBody;
245245
if (isSymbolProc) {
246-
string.catString("(&:" + ((RubySymbol.SymbolProcBody) block.getBody()).getId() + ")");
246+
string.catStringUnsafe("(&:" + ((RubySymbol.SymbolProcBody) block.getBody()).getId() + ")");
247247
} else if ((file = block.getBody().getFile()) != null) {
248-
string.catString(" " + file + ":" + (block.getBody().getLine() + 1));
248+
string.catStringUnsafe(" " + file + ":" + (block.getBody().getLine() + 1));
249249
}
250250

251-
if (isLambda()) string.catString(" (lambda)");
252-
string.catString(">");
251+
if (isLambda()) string.catStringUnsafe(" (lambda)");
252+
string.catStringUnsafe(">");
253253

254254
return string;
255255
}

core/src/main/java/org/jruby/RubyString.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,20 @@ public final int catWithCodeRange(ByteList other, int codeRange) {
15241524
return EncodingUtils.encCrStrBufCat(metaClass.runtime, this, other, other.getEncoding(), codeRange);
15251525
}
15261526

1527+
/**
1528+
* Append a Java String to this RubyString assuming it will be the encoding of the RubyString. If it is
1529+
* not then then it will end up as an invalid string. Some methods assume an encoding of BINARY so that
1530+
* broken bytes are possible/expected (e.g. an error message with two names which are not compatible to be
1531+
* combined into a single Ruby String). Proc#to_s is an example of this.
1532+
* @param str to be appended
1533+
* @return this string after it has appended str
1534+
*/
1535+
public final RubyString catStringUnsafe(String str) {
1536+
ByteList other = encodeBytelist(str, getEncoding());
1537+
catWithCodeRange(other, CR_UNKNOWN);
1538+
return this;
1539+
}
1540+
15271541
public final RubyString catString(String str) {
15281542
ByteList other = encodeBytelist(str, UTF8);
15291543
catWithCodeRange(other, CR_VALID);

0 commit comments

Comments
 (0)