Skip to content

Fixes split_args handling of quotes that start or end inside an argument. - #439

Open
RaphaelFakhri wants to merge 1 commit into
python:mainfrom
RaphaelFakhri:fix-split-args-embedded-quotes
Open

RaphaelFakhri wants to merge 1 commit into
python:mainfrom
RaphaelFakhri:fix-split-args-embedded-quotes

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

split_args parses the ExecutableArguments and WindowedExecutableArguments values of PEP 514 registrations. It only handles quotes that wrap a whole argument. When a quote starts or ends inside an argument, the parser keeps a stray quote (-W"ignore" becomes -W"ignore) or drops text ("a b"c becomes a b). It also collapses \\ outside quotes and turns doubled spaces into empty arguments.

This change replaces the parser with a character-by-character implementation of the C runtime rules:

  • Whitespace (space or tab) outside quotes separates arguments.
  • 2n backslashes followed by a quote produce n backslashes and toggle quoting.
  • 2n+1 backslashes followed by a quote produce n backslashes and a literal quote.
  • A doubled quote inside a quoted section produces a literal quote.
  • Other backslashes are kept as is.

The new test_split_args cases include the examples from Parsing C command-line arguments. The existing quote_args round-trip cases still pass.

Fixes #438

@python-cla-bot

python-cla-bot Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unregistered runtime arguments with embedded quotes are passed incorrectly

1 participant