Skip to content

Document and fix command sanitizing with shlex.split#3245

Merged
Rowlando13 merged 1 commit intopallets:stablefrom
kdeldycke:no-shell-command
Apr 8, 2026
Merged

Document and fix command sanitizing with shlex.split#3245
Rowlando13 merged 1 commit intopallets:stablefrom
kdeldycke:no-shell-command

Conversation

@kdeldycke
Copy link
Copy Markdown
Collaborator

@kdeldycke kdeldycke commented Mar 5, 2026

Also removes last use of shell=True use for command invokation for defense-in-depth.

Context

I was trying to eliminate the last usage of shell=True in subprocess.Popen, then had to resort to using shlex.split in edit_files. This led me into the rabbit hole of shlex.split usage in _termui_impl.py file. Which I use as an opportunity to document past choices from older issues and PRs.

Tests

I also use that opportunity to collect test cases discussed in older related issues and PRs to illustrate and cover how we are expecting command path to be unquoted and interpreted on POSIX systems and Windows.

Related

@kdeldycke kdeldycke added this to the 8.3.2 milestone Mar 5, 2026
@kdeldycke kdeldycke added bug f:prompt feature: prompt for input labels Mar 5, 2026
@Rowlando13 Rowlando13 modified the milestones: 8.3.2, 8.3.3 Mar 15, 2026
Removes last use of `shell=True` use for command invokation for defense-in-depth.
Refs: pallets#1026, pallets#1477 and pallets#2775
@Rowlando13 Rowlando13 merged commit 63ea71f into pallets:stable Apr 8, 2026
12 checks passed
@kdeldycke kdeldycke deleted the no-shell-command branch April 9, 2026 08:48
@kdeldycke
Copy link
Copy Markdown
Collaborator Author

Thanks @Rowlando13 for the merge again ! 🎉

kdeldycke added a commit to kdeldycke/click that referenced this pull request Apr 9, 2026
Add missing entries for pallets#3238 and pallets#3299
Fix wrong version for pallets#3245 changelog entry
Lint section format
@kdeldycke
Copy link
Copy Markdown
Collaborator Author

There was a tiny issue with the location of the changelog entry for that PR that I fixed in 1339fd3 and moved it to the 8.3.3 section.


.. note::
``posix=False`` `was considered but rejected
<https://github.com/pallets/click/pull/1477#issuecomment-620231711>`_
Copy link
Copy Markdown
Member

@davidism davidism Apr 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment, and the details above about PAGER splitting, isn't relevant to users. I also prefer not to have GitHub links in docs or comments at all. Add a simple explanation comment like "split doesn't use posix mode because ..." above the relevant code.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this linked issue suggests that shlex.split will not be correct across platforms. How did you determine that it is now correct?

because it retains quote characters in tokens. The
:func:`shlex.quote` approach was also reverted in :pr:`1543`.

.. seealso::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove these.


Returns `True` if the command was found, `False` otherwise and thus another
pager should be attempted.
.. seealso::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

The editor command is split into an ``argv`` list with
:func:`shlex.split` in POSIX mode; see :func:`pager` for rationale.

.. seealso::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this

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

Labels

bug f:prompt feature: prompt for input

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants