Skip to content

Commit 98d10e9

Browse files
committed
[GR-65190]: Fix raw unicode escape decoder
PullRequest: graalpython/3823
2 parents 228cb6c + 7f3191a commit 98d10e9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_string.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,3 +1204,9 @@ def test_str_from_mmap():
12041204
mm.write(b"GraalPy")
12051205
mm.seek(0)
12061206
assert str(mm, encoding='utf-8') == 'GraalPy'
1207+
1208+
1209+
def test_raw_unicode_escape_does_not_alter_encoded_string():
1210+
original = "[\\xA0]"
1211+
decoded = bytes(original, encoding="raw-unicode-escape").decode("raw-unicode-escape")
1212+
assert original == decoded

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/charset/PythonRawUnicodeEscapeCharsetDecoder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2020, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* The Universal Permissive License (UPL), Version 1.0
@@ -75,6 +75,7 @@ protected CoderResult decodeLoop(ByteBuffer source, CharBuffer target) {
7575
seenBackslash = false;
7676
} else {
7777
target.put('\\');
78+
target.put((char) (b & 0xFF));
7879
seenBackslash = false;
7980
}
8081
} else if (b == (byte) '\\') {

0 commit comments

Comments
 (0)