Skip to content

Commit ddc6179

Browse files
committed
Fix issue with getting a codepoint from a string with a dummy encoding.
1 parent e1dc587 commit ddc6179

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/main/java/org/truffleruby/core/rope/RopeNodes.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.jcodings.specific.ASCIIEncoding;
2929
import org.jcodings.specific.USASCIIEncoding;
3030
import org.jcodings.specific.UTF8Encoding;
31+
import org.truffleruby.core.encoding.EncodingNodes;
3132
import org.truffleruby.core.rope.RopeNodesFactory.SetByteNodeGen;
3233
import org.truffleruby.core.string.StringAttributes;
3334
import org.truffleruby.core.string.StringSupport;
@@ -1185,21 +1186,23 @@ public int getCodePointUTF8(Rope rope, int index,
11851186
@Cached("create()") GetByteNode getByteNode,
11861187
@Cached("create()") BytesNode bytesNode,
11871188
@Cached("create()") CodeRangeNode codeRangeNode,
1189+
@Cached("create()") EncodingNodes.GetActualEncodingNode getActualEncodingNode,
11881190
@Cached("createBinaryProfile()") ConditionProfile singleByteCharProfile,
11891191
@Cached("create()") BranchProfile errorProfile) {
11901192
final int firstByte = getByteNode.executeGetByte(rope, index);
11911193
if (singleByteCharProfile.profile(firstByte < 128)) {
11921194
return firstByte;
11931195
}
11941196

1195-
return getCodePointMultiByte(rope, index, errorProfile, bytesNode, codeRangeNode);
1197+
return getCodePointMultiByte(rope, index, errorProfile, bytesNode, codeRangeNode, getActualEncodingNode);
11961198
}
11971199

11981200
@Specialization(guards = { "!singleByteOptimizableNode.execute(rope)", "!rope.getEncoding().isUTF8()" })
11991201
public int getCodePointMultiByte(Rope rope, int index,
12001202
@Cached("create()") BranchProfile errorProfile,
12011203
@Cached("create()") BytesNode bytesNode,
1202-
@Cached("create()") CodeRangeNode codeRangeNode) {
1204+
@Cached("create()") CodeRangeNode codeRangeNode,
1205+
@Cached("create()") EncodingNodes.GetActualEncodingNode getActualEncodingNode) {
12031206
final byte[] bytes = bytesNode.execute(rope);
12041207
final Encoding encoding = rope.getEncoding();
12051208
final CodeRange codeRange = codeRangeNode.execute(rope);
@@ -1210,7 +1213,9 @@ public int getCodePointMultiByte(Rope rope, int index,
12101213
throw new RaiseException(getContext(), getContext().getCoreExceptions().argumentError("invalid byte sequence in " + encoding, null));
12111214
}
12121215

1213-
return mbcToCode(encoding, bytes, index, rope.byteLength());
1216+
final Encoding actualEncoding = getActualEncodingNode.execute(rope);
1217+
1218+
return mbcToCode(actualEncoding, bytes, index, rope.byteLength());
12141219
}
12151220

12161221
@TruffleBoundary

0 commit comments

Comments
 (0)