Install source and version
- Installed from the Windows Store
- Installed with the MSIX from python.org
- Installed with the MSI from python.org
- Installed with
winget install 9NQ7512CXL7T
Version: current main (e634365). Found by reading the source and reproduced at the function level, not through an installed build.
Describe the bug
For runtimes that are registered through PEP 514 but not managed by the install manager, pep514utils reads the ExecutableArguments and WindowedExecutableArguments values with scriptutils.split_args. Those arguments are then quoted again with quote_args and passed to the runtime when it is launched.
split_args only handles quotes that wrap a whole argument. A quote that starts or ends inside an argument, which is valid on Windows, gives the wrong result:
| Input |
split_args result |
Windows C runtime result |
--opt="a b" -E |
['--opt="a b', '-E'] |
['--opt=a b', '-E'] |
-W"ignore" |
['-W"ignore'] |
['-Wignore'] |
"a b"c d |
['a b', 'd'] |
['a bc', 'd'] |
a"b"" c d |
['a"b', 'c', 'd'] |
['ab" c d'] |
-X utf8 |
['-X', '', 'utf8'] |
['-X', 'utf8'] |
As a result, the launched runtime can receive an argument with a stray quote (for example, -W"ignore, which Python ignores as an invalid warning filter), or text can be dropped. The same values are shown in py list -f json as executable_args.
To Reproduce
>>> from manage.scriptutils import split_args
>>> split_args('-W"ignore"')
['-W"ignore']
>>> split_args('"a b"c d')
['a b', 'd']
Expected behavior
split_args splits arguments the same way the C runtime does, as described in Parsing C command-line arguments.
Additional context
None.