Merge pull request #3706 from Icinga/fix/multiline-values-in-ini-files-broken-3705
Fix multiline values in ini files broken
This commit is contained in:
commit
ccc2f487f6
|
@ -157,11 +157,10 @@ class Directive
|
|||
{
|
||||
$str = trim($str);
|
||||
$str = str_replace('\\', '\\\\', $str);
|
||||
$str = str_replace('"', '\\"', $str);
|
||||
$str = str_replace('"', '\"', $str);
|
||||
$str = str_replace("\r", '\r', $str);
|
||||
$str = str_replace("\n", '\n', $str);
|
||||
|
||||
// line breaks in the value should always match the current system EOL sequence
|
||||
// to assure editable configuration files
|
||||
$str = preg_replace("/(\r\n)|(\n)/", PHP_EOL, $str);
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -284,8 +284,8 @@ class IniParser
|
|||
*/
|
||||
protected static function unescapeSectionName($str)
|
||||
{
|
||||
$str = str_replace('\\"', '"', $str);
|
||||
$str = str_replace('\\;', ';', $str);
|
||||
$str = str_replace('\"', '"', $str);
|
||||
$str = str_replace('\;', ';', $str);
|
||||
|
||||
return str_replace('\\\\', '\\', $str);
|
||||
}
|
||||
|
@ -299,8 +299,11 @@ class IniParser
|
|||
*/
|
||||
protected static function unescapeOptionValue($str)
|
||||
{
|
||||
$str = str_replace('\\"', '"', $str);
|
||||
$str = str_replace('\n', "\n", $str);
|
||||
$str = str_replace('\r', "\r", $str);
|
||||
$str = str_replace('\"', '"', $str);
|
||||
$str = str_replace('\\\\', '\\', $str);
|
||||
|
||||
return str_replace('\\\\', '\\', $str);
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -132,7 +132,42 @@ EOD;
|
|||
$this->assertEquals(
|
||||
2,
|
||||
count(explode("\n", $doc->getSection('section')->getDirective('key1')->getValue())),
|
||||
'IniParser does not recognize multi-line values'
|
||||
'IniParser::parseIni does not recognize multi-line values'
|
||||
);
|
||||
|
||||
(new IniWriter(Config::fromArray([
|
||||
'section' => [
|
||||
'key1' => "with some\nnewline in the value"
|
||||
]
|
||||
]), $this->tempFile))->write();
|
||||
|
||||
$doc = IniParser::parseIniFile($this->tempFile);
|
||||
$this->assertEquals(
|
||||
2,
|
||||
count(explode("\n", $doc->getSection('section')->get('key1'))),
|
||||
'IniParser::parseIniFile does not recognize multi-line values'
|
||||
);
|
||||
}
|
||||
|
||||
public function testEnvironmentVariableResolutionDoesNotWork()
|
||||
{
|
||||
(new IniWriter(Config::fromArray([
|
||||
'section' => [
|
||||
'key1' => '${PATH}_${APACHE_RUN_DIR}',
|
||||
'key2' => '${APACHE_RUN_USER}'
|
||||
]
|
||||
]), $this->tempFile))->write();
|
||||
|
||||
$configObject = IniParser::parseIniFile($this->tempFile);
|
||||
$this->assertEquals(
|
||||
'${PATH}_${APACHE_RUN_DIR}',
|
||||
$configObject->getSection('section')->get('key1'),
|
||||
'IniParser::parseIniFile does resolve environment variables'
|
||||
);
|
||||
$this->assertEquals(
|
||||
'${APACHE_RUN_USER}',
|
||||
$configObject->getSection('section')->get('key2'),
|
||||
'IniParser::parseIniFile does resolve environment variables'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -275,9 +275,14 @@ inkey' => 'blarg'
|
|||
);
|
||||
|
||||
$rendered = $writer->render();
|
||||
$this->assertRegExp(
|
||||
'~linebreak\\\\nin line~',
|
||||
$rendered,
|
||||
'newlines in values are not escaped'
|
||||
);
|
||||
$this->assertEquals(
|
||||
4,
|
||||
count(explode("\n", $rendered)),
|
||||
5,
|
||||
'generated config should not contain more than three line breaks'
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue