Skip to content

Commit cf8d6b1

Browse files
committed
Fix dealing with non-BMP characters in unicode-escape
1 parent a4f97ee commit cf8d6b1

File tree

1 file changed

+4
-2
lines changed
  • graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes

1 file changed

+4
-2
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/bytes/BytesUtils.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,9 +246,10 @@ public static byte[] unicodeEscape(String str) {
246246
// ('\U00xxxxxx')
247247
byte[] bytes = new byte[str.length() * 10];
248248
int j = 0;
249-
for (int i = 0; i < str.length(); i++) {
249+
for (int i = 0; i < str.length();) {
250250
int ch = str.codePointAt(i);
251251
j = unicodeEscape(ch, j, bytes);
252+
i += Character.charCount(ch);
252253
}
253254
bytes = Arrays.copyOf(bytes, j);
254255
return bytes;
@@ -258,9 +259,10 @@ public static byte[] unicodeEscape(String str) {
258259
public static byte[] unicodeNonAsciiEscape(String str) {
259260
byte[] bytes = new byte[str.length() * 10];
260261
int j = 0;
261-
for (int i = 0; i < str.length(); i++) {
262+
for (int i = 0; i < str.length();) {
262263
int ch = str.codePointAt(i);
263264
j = unicodeNonAsciiEscape(ch, j, bytes);
265+
i += Character.charCount(ch);
264266
}
265267
bytes = Arrays.copyOf(bytes, j);
266268
return bytes;

0 commit comments

Comments
 (0)