summaryrefslogtreecommitdiffstats
path: root/Parser/pegen/parse_string.c
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/pegen/parse_string.c')
-rw-r--r--Parser/pegen/parse_string.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/Parser/pegen/parse_string.c b/Parser/pegen/parse_string.c
index f1df2c4..af350b3 100644
--- a/Parser/pegen/parse_string.c
+++ b/Parser/pegen/parse_string.c
@@ -444,12 +444,23 @@ fstring_find_literal(Parser *p, const char **str, const char *end, int raw,
if (!raw && ch == '\\' && s < end) {
ch = *s++;
if (ch == 'N') {
+ /* We need to look at and skip matching braces for "\N{name}"
+ sequences because otherwise we'll think the opening '{'
+ starts an expression, which is not the case with "\N".
+ Keep looking for either a matched '{' '}' pair, or the end
+ of the string. */
+
if (s < end && *s++ == '{') {
while (s < end && *s++ != '}') {
}
continue;
}
- break;
+
+ /* This is an invalid "\N" sequence, since it's a "\N" not
+ followed by a "{". Just keep parsing this literal. This
+ error will be caught later by
+ decode_unicode_with_escapes(). */
+ continue;
}
if (ch == '{' && warn_invalid_escape_sequence(p, ch, t) < 0) {
return -1;
@@ -493,7 +504,8 @@ done:
*literal = PyUnicode_DecodeUTF8Stateful(literal_start,
s - literal_start,
NULL, NULL);
- } else {
+ }
+ else {
*literal = decode_unicode_with_escapes(p, literal_start,
s - literal_start, t);
}