[New-bugs-announce] [issue42983] sys.argv incorrectly parses command lines with args in environment variables.

Jason Williams report at bugs.python.org
Wed Jan 20 15:07:16 EST 2021


New submission from Jason Williams <jasonjwwilliams at gmail.com>:

Passing arguments to a Python script using an environment variable like:

export en_auth="--arg1 test --arg2 \"$(<private_key.pem)\""
./test.py $en_auth

Incorrectly treats the value of arg2 as another argument rather than a value because the file value being inserted starts with "--":
-----BEGIN EC PARAMETERS----- BggqhkjOPQMBBw== -----END EC PARAMETERS-----

sys.argv parses it as:
['--arg1', 'test', '--arg2', '"-----BEGIN', 'EC', 'PARAMETERS-----', 'BggqhkjOPQMBBw==', '-----END', 'EC', 'PARAMETERS-----"']

If the arguments are provided directly to the script it parses correctly:
./test.py --arg1 test --arg2 "$(<private_key.pem)"

['--base-api-url', 'test', '--provisioning-device-private-key', '-----BEGIN EC PARAMETERS-----']

This looks like two bugs...sys.argv is splitting the value incorrectly because its ignoring the quoting, and argparse is treating values that start with -- as arguments.

----------
files: test.py
messages: 385366
nosy: Jason Williams
priority: normal
severity: normal
status: open
title: sys.argv incorrectly parses command lines with args in environment variables.
versions: Python 3.8
Added file: https://bugs.python.org/file49753/test.py

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42983>
_______________________________________


More information about the New-bugs-announce mailing list