Skip to content

Commit 61aa95e

Browse files
committed
encode bytelike objs with utf-8 if no encoding given
1 parent 16178cd commit 61aa95e

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1934,14 +1934,15 @@ Object strOneArg(Object strClass, Object obj, @SuppressWarnings("unused") PNone
19341934
return result;
19351935
}
19361936

1937-
@Specialization(guards = {"!isNativeClass(strClass)", "!isNoValue(encoding)"}, limit = "3")
1937+
@Specialization(guards = {"!isNativeClass(strClass)", "!isNoValue(encoding) || !isNoValue(errors)"}, limit = "3")
19381938
Object doBuffer(VirtualFrame frame, Object strClass, Object obj, Object encoding, Object errors,
19391939
@CachedLibrary("obj") PythonObjectLibrary bufferLib) {
19401940
if (bufferLib.isBuffer(obj)) {
19411941
try {
19421942
// TODO(fa): we should directly call '_codecs.decode'
19431943
PBytes bytesObj = factory().createBytes(bufferLib.getBufferBytes(obj));
1944-
return decodeBytes(frame, strClass, bytesObj, encoding, errors);
1944+
Object en = encoding == PNone.NO_VALUE ? "utf-8" : encoding;
1945+
return decodeBytes(frame, strClass, bytesObj, en, errors);
19451946
} catch (UnsupportedMessageException e) {
19461947
// fall through
19471948
}

0 commit comments

Comments
 (0)