parent
3173b885e8
commit
15e87a15bb
|
@ -368,7 +368,7 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
|
|||
|
||||
protected function renderKeyName($key)
|
||||
{
|
||||
if (preg_match('/^[a-z0-9_]+\d*$/i', $key)) {
|
||||
if (preg_match('/^[a-z][a-z0-9_]*$/i', $key)) {
|
||||
return 'vars.' . c::escapeIfReserved($key);
|
||||
} else {
|
||||
return 'vars[' . c::renderString($key) . ']';
|
||||
|
|
|
@ -44,6 +44,20 @@ class CustomVariablesTest extends BaseTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testNumericKeysAreRenderedWithArraySyntax()
|
||||
{
|
||||
$vars = $this->newVars();
|
||||
$vars->{'1'} = 1;
|
||||
$expected = $this->indentVarsList(array(
|
||||
'vars["1"] = 1'
|
||||
));
|
||||
|
||||
$this->assertEquals(
|
||||
$expected,
|
||||
$vars->toConfigString(true)
|
||||
);
|
||||
}
|
||||
|
||||
public function testVariablesToExpression()
|
||||
{
|
||||
$vars = $this->newVars();
|
||||
|
|
Loading…
Reference in New Issue