Skip to content

Commit 3d31b82

Browse files
committed
Fix: don't restrict byte range.
1 parent 74c6c82 commit 3d31b82

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -355,13 +355,13 @@ private Object[] encodeString(String self, String errors) {
355355
int codePoints = n / Integer.BYTES;
356356

357357
while (encoded.hasRemaining()) {
358-
int int1 = encoded.getInt();
359-
if (int1 > 31 && int1 <= 126) {
360-
buf.put((byte) int1);
358+
int codePoint = encoded.getInt();
359+
if (codePoint <= 0xFF) {
360+
buf.put((byte) codePoint);
361361
} else {
362362
buf.put((byte) '\\');
363363
buf.put((byte) 'u');
364-
String hexString = Integer.toHexString(int1);
364+
String hexString = Integer.toHexString(codePoint);
365365
for (int i = 0; i < hexString.length(); i++) {
366366
assert hexString.charAt(i) < 128;
367367
buf.put((byte) hexString.charAt(i));
@@ -467,12 +467,6 @@ Object decode(PIBytesLike bytes, Object errors,
467467
return factory().createTuple(new Object[]{string, string.length()});
468468
}
469469

470-
// @Fallback
471-
// Object decode(Object bytes, @SuppressWarnings("unused") Object encoding,
472-
// @SuppressWarnings("unused") Object errors) {
473-
// throw raise(TypeError, "a bytes-like object is required, not '%p'", bytes);
474-
// }
475-
476470
private ByteBuffer getBytesBuffer(PIBytesLike bytesLike) {
477471
if (toByteArrayNode == null) {
478472
CompilerDirectives.transferToInterpreterAndInvalidate();

0 commit comments

Comments
 (0)