summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2023-05-24 10:40:51 (GMT)
committerGitHub <noreply@github.com>2023-05-24 10:40:51 (GMT)
commit3d2ed8991f9f0f4bbefe4c6f5c8bbbb92259bac6 (patch)
tree1e8a1de7639ecf27bc8c0ccf83a502d4d86d932d /Python
parent2d685eca8a6ef25963609246d18097032358881c (diff)
downloadcpython-3d2ed8991f9f0f4bbefe4c6f5c8bbbb92259bac6.zip
cpython-3d2ed8991f9f0f4bbefe4c6f5c8bbbb92259bac6.tar.gz
cpython-3d2ed8991f9f0f4bbefe4c6f5c8bbbb92259bac6.tar.bz2
[3.12] gh-104825: Remove implicit newline in the line attribute in tokens emitted in the tokenize module (GH-104846). (#104850)
(cherry picked from commit c8cf9b42eb2bfbd4c3e708ec28d32430248a1d7a)
Diffstat (limited to 'Python')
-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);