summaryrefslogtreecommitdiffstats
path: root/Python/Python-tokenize.c
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2023-05-24 09:59:18 (GMT)
committerGitHub <noreply@github.com>2023-05-24 09:59:18 (GMT)
commitc8cf9b42eb2bfbd4c3e708ec28d32430248a1d7a (patch)
treea57961289b87372b19a3a538bee40264646d1478 /Python/Python-tokenize.c
parentc45701e9ef004a523ebb28f3be902b3cf2cf7a9b (diff)
downloadcpython-c8cf9b42eb2bfbd4c3e708ec28d32430248a1d7a.zip
cpython-c8cf9b42eb2bfbd4c3e708ec28d32430248a1d7a.tar.gz
cpython-c8cf9b42eb2bfbd4c3e708ec28d32430248a1d7a.tar.bz2
gh-104825: Remove implicit newline in the line attribute in tokens emitted in the tokenize module (#104846)
Diffstat (limited to 'Python/Python-tokenize.c')
-rw-r--r--Python/Python-tokenize.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/Python/Python-tokenize.c b/Python/Python-tokenize.c
index f7e32d3..0023e30 100644
--- a/Python/Python-tokenize.c
+++ b/Python/Python-tokenize.c
@@ -123,6 +123,8 @@ _tokenizer_error(struct tok_state *tok)
int result = 0;
Py_ssize_t size = tok->inp - tok->buf;
+ assert(tok->buf[size-1] == '\n');
+ size -= 1; // Remove the newline character from the end of the line
error_line = PyUnicode_DecodeUTF8(tok->buf, size, "replace");
if (!error_line) {
result = -1;
@@ -193,6 +195,8 @@ tokenizeriter_next(tokenizeriterobject *it)
}
Py_ssize_t size = it->tok->inp - it->tok->buf;
+ assert(it->tok->buf[size-1] == '\n');
+ size -= 1; // Remove the newline character from the end of the line
PyObject *line = PyUnicode_DecodeUTF8(it->tok->buf, size, "replace");
if (line == NULL) {
Py_DECREF(str);