You've already forked postfixadmin
mirror of
https://github.com/postfixadmin/postfixadmin.git
synced 2025-07-29 22:41:11 +03:00
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.
This commit is contained in:
@ -323,26 +323,22 @@ class PostfixAdmin {
|
|||||||
private function __parseParams($params) {
|
private function __parseParams($params) {
|
||||||
$count = count($params);
|
$count = count($params);
|
||||||
for ($i = 0; $i < $count; $i++) {
|
for ($i = 0; $i < $count; $i++) {
|
||||||
if (isset($params[$i])) {
|
# if (isset($params[$i])) {
|
||||||
if ($params[$i] != '' && $params[$i]{0} === '-') {
|
if ($params[$i] != '' && $params[$i]{0} === '-' && $params[$i] != '-1') {
|
||||||
$key = substr($params[$i], 1);
|
$key = substr($params[$i], 1);
|
||||||
$this->params[$key] = true;
|
if (isset($params[$i+1])) {
|
||||||
unset($params[$i]);
|
|
||||||
if (isset($params[++$i])) {
|
|
||||||
# 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)
|
# 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') {
|
if ($params[$i+1]{0} === '-' && $params[$i+1] != '-1') {
|
||||||
$this->params[$key] = $params[$i];
|
$this->params[$key] = true;
|
||||||
unset($params[$i]);
|
|
||||||
} else {
|
} else {
|
||||||
$i--;
|
$this->params[$key] = $params[$i+1];
|
||||||
$this->__parseParams($params);
|
$i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->args[] = $params[$i];
|
$this->args[] = $params[$i];
|
||||||
unset($params[$i]);
|
|
||||||
}
|
}
|
||||||
}
|
# }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user