Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Handle f-strings correctly as well
  • Loading branch information
lysnikolaou committed May 3, 2023
commit 78fbd3ca6185d3483fab191fc8c9be55b093ba0c
19 changes: 10 additions & 9 deletions Lib/test/test_cmd_line_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -670,16 +670,17 @@ def test_syntaxerror_null_bytes(self):
)

def test_syntaxerror_null_bytes_in_multiline_string(self):
script = "\n'''\nmultilinestring\0\n'''"
scripts = ["\n'''\nmultilinestring\0\n'''", "\nf'''\nmultilinestring\0\n'''"] # Both normal and f-strings
with os_helper.temp_dir() as script_dir:
script_name = _make_test_script(script_dir, 'script', script)
_, _, stderr = assert_python_failure(script_name)
self.assertEqual(
stderr.splitlines()[-2:],
[ b" multilinestring",
b'SyntaxError: source code cannot contain null bytes'
]
)
for script in scripts:
script_name = _make_test_script(script_dir, 'script', script)
_, _, stderr = assert_python_failure(script_name)
self.assertEqual(
stderr.splitlines()[-2:],
[ b" multilinestring",
b'SyntaxError: source code cannot contain null bytes'
]
)

def test_consistent_sys_path_for_direct_execution(self):
# This test case ensures that the following all give the same
Expand Down
3 changes: 3 additions & 0 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2558,6 +2558,9 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct

while (end_quote_size != current_tok->f_string_quote_size) {
int c = tok_nextc(tok);
if (tok->done == E_ERROR) {
return MAKE_TOKEN(ERRORTOKEN);
}
if (c == EOF || (current_tok->f_string_quote_size == 1 && c == '\n')) {
if (tok->decoding_erred) {
return MAKE_TOKEN(ERRORTOKEN);
Expand Down