swansonk14 / typed-argument-parser

Typed argument parser for Python
MIT License
497 stars 40 forks source link

Quotes within arguments are removed #72

Open Effervex opened 2 years ago

Effervex commented 2 years ago

Introduced in 1.7.2, when using TAP to parse arguments, arguments with quotes within the argument remove the quote. This was likely introduced when handling quoted arguments. It appears to be the same for either quote style.

For instance: --foo b'a'r is parsed as: foo: 'bar'

It works fine if the argument is quoted though, so perhaps this is not an issue: --foo "b'a'r" is parsed as: foo: 'b\'a\'r'

martinjm97 commented 2 years ago

Hi @Effervex,

Great point! We agree this is an issue. We should check if a string is enclosed in quotation marks before remove quotation marks. As you might have guessed from the lag in the reply, it might take a while. PRs appreciated... we'll try to get to it soon!

Thanks, Kyle and Jesse

arnaud-ma commented 2 months ago

This seems to be an expected case for any shell. For example on bash:

>>> echo b'a'r
bar
>>> echo "b'a'r"
b'a'r
>>> echo b\'a\'r
b'a'r

The only solution is unfortunately to use "b'a'r" or b\'a\'r. And it's the same for any other command from any other tool, because the parsing is done at the shell level.