Skip to content

Commit 112a412

Browse files
committed
[GR-42961] Add missin encoding switch in ToRegexSourceNode.
PullRequest: graalpython/2639
2 parents e4954f1 + 643b7cc commit 112a412

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/MarshalModuleBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,7 +1058,7 @@ private void writeString(TruffleString v) {
10581058
* passthrough. If the string contains surrogates, we mark it and emit it as UTF-32.
10591059
*/
10601060
Encoding encoding;
1061-
if (v.isCompatibleTo(Encoding.UTF_8)) {
1061+
if (v.isValidUncached(TS_ENCODING)) {
10621062
encoding = Encoding.UTF_8;
10631063
} else {
10641064
encoding = Encoding.UTF_32LE;

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/SREModuleBuiltins.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,8 @@ protected Source doGeneric(VirtualFrame frame, Object pattern, TruffleString fla
160160
@Cached CastToTruffleStringNode cast,
161161
@CachedLibrary(limit = "3") PythonBufferAcquireLibrary bufferAcquireLib,
162162
@CachedLibrary(limit = "1") PythonBufferAccessLibrary bufferLib,
163-
@Cached TruffleString.FromByteArrayNode fromByteArrayNode) {
163+
@Cached TruffleString.FromByteArrayNode fromByteArrayNode,
164+
@Cached TruffleString.SwitchEncodingNode switchEncodingNode) {
164165
try {
165166
return doString(cast.execute(pattern), flags, options, inliningTarget, nonEmptyOptionsProfile, appendStringNode, toStringNode, toJavaStringNode);
166167
} catch (CannotCastException ce) {
@@ -173,7 +174,7 @@ protected Source doGeneric(VirtualFrame frame, Object pattern, TruffleString fla
173174
try {
174175
byte[] bytes = bufferLib.getInternalOrCopiedByteArray(buffer);
175176
int bytesLen = bufferLib.getBufferLength(buffer);
176-
TruffleString patternStr = fromByteArrayNode.execute(bytes, 0, bytesLen, Encoding.ISO_8859_1, false);
177+
TruffleString patternStr = switchEncodingNode.execute(fromByteArrayNode.execute(bytes, 0, bytesLen, Encoding.ISO_8859_1, false), TS_ENCODING);
177178
return constructRegexSource(inliningTarget, T_ENCODING_LATIN_1, options, patternStr, flags, nonEmptyOptionsProfile, appendStringNode, toStringNode, toJavaStringNode);
178179
} finally {
179180
bufferLib.release(buffer, frame, this);

0 commit comments

Comments
 (0)