-
-
Notifications
You must be signed in to change notification settings - Fork 33.4k
Closed
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parser
Description
Documentation
This is somewhat related to #116580. There are two references to NULL in the description of f-strings that don't have a clear meaning.
format_spec ::= (literal_char | NULL | replacement_field)*
literal_char ::= <any code point except "{", "}" or NULL>
In both cases (but especially literal_char), it could refer to U+0000, but I'm unaware that a null character is allowed anywhere in Python source. At least, my attempt to inject one failed:
>>> print(ast.dump(ast.parse("f'{x:"'\x00'"}'"), indent=2))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.12/lib/python3.12/ast.py", line 52, in parse
return compile(source, filename, mode, flags,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: source code string cannot contain null bytesFor format_spec, it could refer to an empty specification (f'{x:}'), but (literal_char | replacement_field)* would cover that just as well.
Linked PRs
Metadata
Metadata
Assignees
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dirinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-parser