diff options
author | Matthew Wild <mwild1@gmail.com> | 2025-03-11 18:27:36 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2025-03-11 18:27:36 +0000 |
commit | 06994f0bc145ebf61b7906a715f61f22a70cbe57 (patch) | |
tree | 8f326fa3cb543584b7eb8677395eb6dbf385558c /util | |
parent | afb9bc34a098a4911effdda36c69a04aca821558 (diff) | |
download | prosody-06994f0bc145ebf61b7906a715f61f22a70cbe57.tar.gz prosody-06994f0bc145ebf61b7906a715f61f22a70cbe57.zip |
util.argparse: Fix bug (regression?) in argument parsing with --foo=bar
After recent changes, '--foo bar' was working, but '--foo=bar' was not. The
test had a typo (?) (bar != baz) and because util.argparse is not strict by
default, the typo was not caught.
The typo caused the code to take a different path, and bypassed the buggy
handling of --foo=bar options.
I've preserved the existing test (typo and all!) because it's still an
interesting test, and ensures no unintended behaviour changes compared to the
old code.
However I've added a new variant of the test, with strict mode enabled and the
typo fixed. This test failed due to the bug, and this commit introduces a fix.
Diffstat (limited to 'util')
-rw-r--r-- | util/argparse.lua | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/util/argparse.lua b/util/argparse.lua index 3a7d1ba2..75b1c2f9 100644 --- a/util/argparse.lua +++ b/util/argparse.lua @@ -39,9 +39,13 @@ local function parse(arg, config) local param_k, param_v; if value_params[uparam] or array_params[uparam] then - param_k, param_v = uparam, table.remove(arg, 1); + param_k = uparam; + param_v = param:match("^=(.*)$", #uparam+1); if not param_v then - return nil, "missing-value", raw_param; + param_v = table.remove(arg, 1); + if not param_v then + return nil, "missing-value", raw_param; + end end else param_k, param_v = param:match("^([^=]+)=(.+)$"); |