From 4e9e3db75dfc4fb9a57b9ba1b403828f35cd5840 Mon Sep 17 00:00:00 2001 From: Christian Boltz Date: Sat, 2 May 2020 01:17:34 +0200 Subject: [PATCH] Fix parameter parsing for '-1' '--quota -1' gets parsed as two options ("quota" and "1"), but it's meant to be "quota => -1". Make sure '-1' is considered as a value, not as an option. Also get rid of unset()'ing $params[$i] and (now?) superfluous recursive calls to __parseParams() to make the code less confusing. --- scripts/postfixadmin-cli.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/scripts/postfixadmin-cli.php b/scripts/postfixadmin-cli.php index 5c12b9ad..0ea75fa3 100644 --- a/scripts/postfixadmin-cli.php +++ b/scripts/postfixadmin-cli.php @@ -323,26 +323,22 @@ class PostfixAdmin { private function __parseParams($params) { $count = count($params); for ($i = 0; $i < $count; $i++) { - if (isset($params[$i])) { - if ($params[$i] != '' && $params[$i]{0} === '-') { +# if (isset($params[$i])) { + if ($params[$i] != '' && $params[$i]{0} === '-' && $params[$i] != '-1') { $key = substr($params[$i], 1); - $this->params[$key] = true; - unset($params[$i]); - if (isset($params[++$i])) { + if (isset($params[$i+1])) { # TODO: ideally we should know if a parameter can / must have a value instead of whitelisting known valid values starting with '-' (probably only bool doesn't need a value) - if ($params[$i]{0} !== '-' or $params[$i] != '-1') { - $this->params[$key] = $params[$i]; - unset($params[$i]); + if ($params[$i+1]{0} === '-' && $params[$i+1] != '-1') { + $this->params[$key] = true; } else { - $i--; - $this->__parseParams($params); + $this->params[$key] = $params[$i+1]; + $i++; } } } else { $this->args[] = $params[$i]; - unset($params[$i]); } - } +# } } }