Comparison

util/argparse.lua @ 13762:81856814d74f 13.0

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.
author Matthew Wild <mwild1@gmail.com>
date Tue, 11 Mar 2025 18:27:36 +0000
parent 13733:48c056c10e5a
comparison
equal deleted inserted replaced
13761:8f516d20d288 13762:81856814d74f
37 37
38 local uparam = param:match("^[^=]*"):gsub("%-", "_"); 38 local uparam = param:match("^[^=]*"):gsub("%-", "_");
39 39
40 local param_k, param_v; 40 local param_k, param_v;
41 if value_params[uparam] or array_params[uparam] then 41 if value_params[uparam] or array_params[uparam] then
42 param_k, param_v = uparam, table.remove(arg, 1); 42 param_k = uparam;
43 param_v = param:match("^=(.*)$", #uparam+1);
43 if not param_v then 44 if not param_v then
44 return nil, "missing-value", raw_param; 45 param_v = table.remove(arg, 1);
46 if not param_v then
47 return nil, "missing-value", raw_param;
48 end
45 end 49 end
46 else 50 else
47 param_k, param_v = param:match("^([^=]+)=(.+)$"); 51 param_k, param_v = param:match("^([^=]+)=(.+)$");
48 if not param_k then 52 if not param_k then
49 if param:match("^no%-") then 53 if param:match("^no%-") then