mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
Make explicit calls to renderStringWithVariables
This commit is contained in:
parent
37c91050c7
commit
b7eaab715b
@ -38,6 +38,10 @@ class CustomVariableString extends CustomVariable
|
||||
|
||||
public function toConfigString($renderExpressions = false)
|
||||
{
|
||||
return c::renderString($this->getValue(), $renderExpressions);
|
||||
if ($renderExpressions) {
|
||||
return c::renderStringWithVariables($this->getValue());
|
||||
} else {
|
||||
return c::renderString($this->getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,7 @@ class IcingaConfigHelper
|
||||
|
||||
// TODO: Find out how to allow multiline {{{...}}} strings.
|
||||
// Parameter? Dedicated method? Always if \n is found?
|
||||
public static function renderString($string, $renderExpressions = false)
|
||||
public static function renderString($string)
|
||||
{
|
||||
$special = array(
|
||||
'/\\\/',
|
||||
@ -100,11 +100,7 @@ class IcingaConfigHelper
|
||||
|
||||
$string = preg_replace($special, $replace, $string);
|
||||
|
||||
if ($renderExpressions) {
|
||||
return self::renderStringWithVariables($string);
|
||||
} else {
|
||||
return '"' . $string . '"';
|
||||
}
|
||||
return '"' . $string . '"';
|
||||
}
|
||||
|
||||
public static function renderDictionaryKey($key)
|
||||
@ -262,15 +258,21 @@ class IcingaConfigHelper
|
||||
return $seconds . 's';
|
||||
}
|
||||
|
||||
private static function renderStringWithVariables($string) {
|
||||
$string = preg_replace('/(?<!\$)\$([\w\.]+)\$(?!\$)/', '" + ${1} + "', $string);
|
||||
$string = '"' . $string . '"';
|
||||
public static function renderStringWithVariables($string)
|
||||
{
|
||||
$string = preg_replace(
|
||||
'/(?<!\$)\$([\w\.]+)\$(?!\$)/',
|
||||
'" + ${1} + "',
|
||||
static::renderString($string)
|
||||
);
|
||||
|
||||
if (substr($string, 0, 5) === '"" + ') {
|
||||
$string = substr($string, 5);
|
||||
}
|
||||
if (substr($string, -5) === ' + ""') {
|
||||
$string = substr($string, 0, -5);
|
||||
}
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
@ -1703,7 +1703,12 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer
|
||||
return $this->renderRelationProperty($relKey, $value);
|
||||
}
|
||||
|
||||
return c::renderKeyValue($key, c::renderString($value, $this->isApplyRule()));
|
||||
return c::renderKeyValue(
|
||||
$key,
|
||||
$this->isApplyRule() ?
|
||||
c::renderStringWithVariables($value) :
|
||||
c::renderString($value)
|
||||
);
|
||||
}
|
||||
|
||||
protected function renderLegacyObjectProperty($key, $value)
|
||||
|
@ -83,21 +83,24 @@ class IcingaConfigHelperTest extends BaseTestCase
|
||||
|
||||
public function testRenderStringWithVariables()
|
||||
{
|
||||
$this->assertEquals(c::renderString('Before $var$', true), '"Before " + var');
|
||||
$this->assertEquals(c::renderString('$var$ After', true), 'var + " After"');
|
||||
$this->assertEquals(c::renderString('$var$', true), 'var');
|
||||
$this->assertEquals(c::renderString('$$var$$', true), '"$$var$$"');
|
||||
$this->assertEquals(c::renderString('Before $$var$$ After', true), '"Before $$var$$ After"');
|
||||
$this->assertEquals(c::renderStringWithVariables('Before $var$'), '"Before " + var');
|
||||
$this->assertEquals(c::renderStringWithVariables('$var$ After'), 'var + " After"');
|
||||
$this->assertEquals(c::renderStringWithVariables('$var$'), 'var');
|
||||
$this->assertEquals(c::renderStringWithVariables('$$var$$'), '"$$var$$"');
|
||||
$this->assertEquals(c::renderStringWithVariables('Before $$var$$ After'), '"Before $$var$$ After"');
|
||||
$this->assertEquals(
|
||||
c::renderString('Before $name$ $name$ After', true),
|
||||
'"Before " + name + " " + name + " After"');
|
||||
c::renderStringWithVariables('Before $name$ $name$ After'),
|
||||
'"Before " + name + " " + name + " After"'
|
||||
);
|
||||
$this->assertEquals(
|
||||
c::renderString('Before $var1$ $var2$ After', true),
|
||||
'"Before " + var1 + " " + var2 + " After"');
|
||||
$this->assertEquals(c::renderString('$host.vars.custom$', true), 'host.vars.custom');
|
||||
$this->assertEquals(c::renderString('$var"$', true), '"$var\"$"');
|
||||
c::renderStringWithVariables('Before $var1$ $var2$ After'),
|
||||
'"Before " + var1 + " " + var2 + " After"'
|
||||
);
|
||||
$this->assertEquals(c::renderStringWithVariables('$host.vars.custom$'), 'host.vars.custom');
|
||||
$this->assertEquals(c::renderStringWithVariables('$var"$'), '"$var\"$"');
|
||||
$this->assertEquals(
|
||||
c::renderString('\tI am\rrendering\nproperly\fand I $support$ "multiple" $variables$\$', true),
|
||||
'"\\\\tI am\\\\rrendering\\\\nproperly\\\\fand I " + support + " \"multiple\" " + variables + "\\\\$"');
|
||||
c::renderStringWithVariables('\tI am\rrendering\nproperly\fand I $support$ "multiple" $variables$\$'),
|
||||
'"\\\\tI am\\\\rrendering\\\\nproperly\\\\fand I " + support + " \"multiple\" " + variables + "\\\\$"'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,8 @@ class IcingaServiceTest extends BaseTestCase
|
||||
protected $testHostName = '___TEST___host';
|
||||
|
||||
protected $testServiceName = '___TEST___service';
|
||||
protected $createdServices = [];
|
||||
|
||||
protected $createdServices = array();
|
||||
|
||||
public function testUnstoredHostCanBeLazySet()
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user