[BUG] Slots/salt.utils.args.parse_function choke on an empty string
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 15.7k
- Forks
- 5.6k
- Avg merge
- 2d 44m
- Merged PRs (30d)
- 80
Description
Description
>>> import salt.utils.args
>>> salt.utils.args.parse_function("foo.bar('')")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/frebib/stash/ops/saltstack/salt/utils/args.py", line 532, in parse_function
if not brackets or token != {"[": "]", "{": "}", "(": ")"}[brackets.pop()]:
KeyError: ''
We hit this trying to pass an empty string into a slot call.
Apparently it sort of works, but it gives a literal string with the quotes in it (which makes sense) when you escape the quotes with backslashes.. because of course it does
>>> salt.utils.args.parse_function("foo.bar(\\\"\\\")")
('foo.bar', ['""'], {})
>>> salt.utils.args.parse_function("foo.bar(\\'\\')")
('foo.bar', ["''"], {})
Versions Report
3005.1 and reproduces on current master HEAD
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in salt/utils/args.py at parse_function, reproducing the reported foo.bar('') case and the escaped-quote examples. Trace how an empty quoted argument is tokenized, then add regression coverage showing that parse_function accepts an empty string without raising KeyError and returns the intended argument value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100