$data = file_get_contents($filepath);
$data = str_replace(self::getPhpHeaders(), '', $data);
$data = str_replace(self::getPhpSuffix(), '', $data);
- $data = json_decode($data, true);
+ $data = json_decode(trim($data), true);
if ($data === null) {
$errorCode = json_last_error();
$error = sprintf(
// JSON_PRETTY_PRINT is available from PHP 5.4.
$print = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 0;
$data = self::getPhpHeaders() . json_encode($conf, $print) . self::getPhpSuffix();
- if (!file_put_contents($filepath, $data)) {
+ if (empty($filepath) || !file_put_contents($filepath, $data)) {
throw new \Shaarli\Exceptions\IOException(
$filepath,
t('Shaarli could not create the config file. '.
*/
public static function getPhpHeaders()
{
- return '<?php /*'. PHP_EOL;
+ return '<?php /*';
}
/**
*/
public static function getPhpSuffix()
{
- return PHP_EOL . '*/ ?>';
+ return '*/ ?>';
}
}