mvc: PortField: always return a string for normalizedPort()

This commit is contained in:
Franco Fichtner
2026-10-03 15:18:53 +02:00
parent 0405ed0f2e
commit ebed60e243
3 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -650,7 +650,7 @@ function filter_core_rules_system($fw, $defaults)
'log' => $dnatrule['log'],
'descr' => $dnatrule['descr']
];
$local_port = (string)$rule->{'local-port'}->normalizedPort();
$local_port = $rule->{'local-port'}->normalizedPort();
if (!empty($dnatrule['destination']['port']) && ctype_digit($local_port)) {
$tmprule['destination']['port'] = $local_port;
@@ -271,7 +271,7 @@ class PortField extends BaseListField
/**
* @return string
*/
public function normalizedPort()
public function normalizedPort(): string
{
/* XXX this does not support multiple values */
$value = $this->getValue();
@@ -281,7 +281,7 @@ class PortField extends BaseListField
$known = self::getWellKnown($value);
if (!empty($known)) {
$value = array_shift($known);
$value = (string)array_shift($known);
}
return $value;
@@ -70,7 +70,7 @@ class SourceNatRuleContainerField extends ContainerField
$result[$target_fieldname] = (string)$node;
}
} elseif ($key == 'target_port' && is_a($node, PortField::class) && $node->getValue() != '') {
$result[$target_fieldname] = (string)$node->normalizedPort();
$result[$target_fieldname] = $node->normalizedPort();
} elseif ((string)$node != '') {
/*
* XXX: Omit empty values to allow array_merge() to overlay default values in Plugin.php.