Skip to content

Commit 8e80f75

Browse files
committed
GR-14297: Fix invalid escape sequence '\s' in byte string literals
1 parent 7bac6ef commit 8e80f75

File tree

1 file changed

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

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,18 @@ public static StringBuilder decodeEscapes(ParserErrorCallback errors, String str
199199
}
200200
throw errors.raise(ValueError, "invalid \\x escape at position %d", i);
201201
default:
202-
if (regexMode && (chr == '\\' || chr == 'g' || (chr >= '0' && chr <= '9'))) {
203-
// only allow backslashes, named group references and numbered group
204-
// references in regex mode
202+
if (regexMode) {
203+
if (chr == 'g' || (chr >= '0' && chr <= '9')) {
204+
// only allow backslashes, named group references and numbered group
205+
// references in regex mode
206+
charList.append('\\');
207+
charList.append(chr);
208+
} else {
209+
throw errors.raise(ValueError, "invalid escape sequence '\\%s' at position %d", chr, i);
210+
}
211+
} else {
205212
charList.append('\\');
206213
charList.append(chr);
207-
} else {
208-
throw errors.raise(ValueError, "invalid escape sequence '\\%s' at position %d", chr, i);
209214
}
210215
}
211216
}

0 commit comments

Comments
 (0)