mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Fix .env with number symbols (#10497)
* Fix .env with number symbols * Handle tabs and trim when quoting so we don't include spaces
This commit is contained in:
@@ -146,6 +146,8 @@ class ComposerHelper
|
||||
}
|
||||
}
|
||||
|
||||
$content = self::fixComments($content);
|
||||
|
||||
// only write if the content has changed
|
||||
if ($content !== $original_content) {
|
||||
file_put_contents($file, $content);
|
||||
@@ -172,4 +174,22 @@ class ComposerHelper
|
||||
$cmd = "set -v\n" . implode(PHP_EOL, (array)$cmds);
|
||||
passthru($cmd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fix .env with # in them without a space before it
|
||||
*/
|
||||
private static function fixComments($dotenv)
|
||||
{
|
||||
return implode(PHP_EOL, array_map(function ($line) {
|
||||
$parts = explode('=', $line, 2);
|
||||
if (isset($parts[1])
|
||||
&& preg_match('/(?<!\s)#/', $parts[1]) // number symbol without a space before it
|
||||
&& !preg_match('/^(".*"|\'.*\')$/', $parts[1]) // not already quoted
|
||||
) {
|
||||
return trim($parts[0]) . '="' . trim($parts[1]) . '"';
|
||||
}
|
||||
|
||||
return $line;
|
||||
}, explode(PHP_EOL, $dotenv)));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user