Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions 8 Lib/test/test_py_compile.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ def test_quiet(self):
with self.assertRaises(py_compile.PyCompileError):
py_compile.compile(bad_coding, doraise=True, quiet=1)

def test_utf7_decoded_cr_compiles(self):
with open(self.source_path, 'wb') as file:
file.write(b"#coding=U7+AA0''\n")

pyc_path = py_compile.compile(self.source_path, self.pyc_path, doraise=True)
self.assertEqual(pyc_path, self.pyc_path)
self.assertTrue(os.path.exists(self.pyc_path))


class PyCompileTestsWithSourceEpoch(PyCompileTestsBase,
unittest.TestCase,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fixed a ``SystemError`` in the parser when an encoding cookie (for example,
UTF-7) decodes to carriage returns (``\r``). Newlines are now normalized after
decoding in the string tokenizer.

Patch by Pablo Galindo.
13 changes: 13 additions & 0 deletions 13 Parser/tokenizer/string_tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,19 @@ decode_str(const char *input, int single, struct tok_state *tok, int preserve_cr
return _PyTokenizer_error_ret(tok);
str = PyBytes_AS_STRING(utf8);
}
if (utf8 != NULL) {
char *translated = _PyTokenizer_translate_newlines(
str, single, preserve_crlf, tok);
if (translated == NULL) {
Py_DECREF(utf8);
return _PyTokenizer_error_ret(tok);
}
PyMem_Free(tok->input);
tok->input = translated;
str = translated;
Py_CLEAR(utf8);
}
tok->str = str;
assert(tok->decoding_buffer == NULL);
tok->decoding_buffer = utf8; /* CAUTION */
return str;
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.