Skip to content

Commit 5c20cd8

Browse files
committed
fix _codecs module to raise LookupError error again when an unsupported charset is used
1 parent 29c1f1c commit 5c20cd8

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -412,10 +412,8 @@ Object encode(Object str, @SuppressWarnings("unused") Object encoding, @Suppress
412412
@TruffleBoundary
413413
private PBytes encodeString(String self, String encoding, String errors) {
414414
CodingErrorAction errorAction = convertCodingErrorAction(errors);
415-
Charset charset;
416-
try {
417-
charset = getCharset(encoding);
418-
} catch (UnsupportedCharsetException | IllegalCharsetNameException e) {
415+
Charset charset = getCharset(encoding);
416+
if (charset == null) {
419417
throw raise(LookupError, "unknown encoding: %s", encoding);
420418
}
421419
try {
@@ -545,10 +543,8 @@ private ByteBuffer getBytesBuffer(PIBytesLike bytesLike) {
545543
@TruffleBoundary
546544
String decodeBytes(ByteBuffer bytes, String encoding, String errors) {
547545
CodingErrorAction errorAction = convertCodingErrorAction(errors);
548-
Charset charset;
549-
try {
550-
charset = getCharset(encoding);
551-
} catch (UnsupportedCharsetException | IllegalCharsetNameException e) {
546+
Charset charset = getCharset(encoding);
547+
if (charset == null) {
552548
throw raise(LookupError, "unknown encoding: %s", encoding);
553549
}
554550
try {
@@ -627,10 +623,9 @@ abstract static class CodecsLookupNode extends PythonBuiltinNode {
627623
// This is replaced in the core _codecs.py with the full functionality
628624
@Specialization
629625
Object lookup(String encoding) {
630-
try {
631-
getCharset(encoding);
626+
if (getCharset(encoding) != null) {
632627
return true;
633-
} catch (UnsupportedCharsetException | IllegalCharsetNameException e) {
628+
} else {
634629
return PNone.NONE;
635630
}
636631
}

0 commit comments

Comments
 (0)