Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shlex.quote: Add 'always' keyword argument #119670

Open
jb2170 opened this issue May 28, 2024 · 1 comment
Open

shlex.quote: Add 'always' keyword argument #119670

jb2170 opened this issue May 28, 2024 · 1 comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@jb2170
Copy link
Contributor

jb2170 commented May 28, 2024

Feature or enhancement

Proposal:

Add the ability to force shlex.quote to always return an escaped / quoted string, avoiding the expensive regex-ing of a straggly set of characters (currently r'[^\w@%+=:,./-]') .

Different shells have slightly different sets of special characters, eg sometimes including #, sometimes not. To quell one's pedantic paranoia of strings being incorrectly escaped due to an incomplete regex check, we extend the signature of shlex.quote in a perfectly backwards compatible way which skips the regex and goes straight to the escaping.

Changes shlex.quote's signature from

def quote(s):

to

def quote(s, always=False):

always is of bool type, and by default is False, which produces the existing behaviour of the function.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Linked PRs

@jb2170 jb2170 added the type-feature A feature request or enhancement label May 28, 2024
@jb2170
Copy link
Contributor Author

jb2170 commented May 28, 2024

PR incoming

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
2 participants