summaryrefslogtreecommitdiffstats
path: root/Python/ast.c
diff options
context:
space:
mode:
authorAnthony Sottile <asottile@umich.edu>2019-01-13 04:05:13 (GMT)
committerINADA Naoki <methane@users.noreply.github.com>2019-01-13 04:05:13 (GMT)
commit995d9b92979768125ced4da3a56f755bcdf80f6e (patch)
tree2184ab1771b87883a92391f41229a12ce4cbd9d3 /Python/ast.c
parent1cffd0eed313011c0c2bb071c8affeb4a7ed05c7 (diff)
downloadcpython-995d9b92979768125ced4da3a56f755bcdf80f6e.zip
cpython-995d9b92979768125ced4da3a56f755bcdf80f6e.tar.gz
cpython-995d9b92979768125ced4da3a56f755bcdf80f6e.tar.bz2
bpo-16806: Fix `lineno` and `col_offset` for multi-line string tokens (GH-10021)
Diffstat (limited to 'Python/ast.c')
-rw-r--r--Python/ast.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Python/ast.c b/Python/ast.c
index 69dfe3c..d71f44a 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -4284,9 +4284,13 @@ fstring_fix_node_location(const node *parent, node *n, char *expr_str)
start--;
}
cols += (int)(substr - start);
- /* Fix lineno in mulitline strings. */
- while ((substr = strchr(substr + 1, '\n')))
- lines--;
+ /* adjust the start based on the number of newlines encountered
+ before the f-string expression */
+ for (char* p = parent->n_str; p < substr; p++) {
+ if (*p == '\n') {
+ lines++;
+ }
+ }
}
}
fstring_shift_node_locations(n, lines, cols);