saltstack / saltstack/salt

[BUG] Slots/salt.utils.args.parse_function choke on an empty string

Open
#63,500 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs-triage State-Compiler
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.