-
-
Notifications
You must be signed in to change notification settings - Fork 6
Open
Labels
help wantedExtra attention is neededExtra attention is needed
Description
When exporting a .env file, values are never wrapped in quotes. When a value contains certain characters, like =, $, or \n (new line), this causes the resultant contents to be invalid.
E.g.
<?php
use sixlive\DotenvEditor\DotenvEditor;
include "vendor/autoload.php";
$editor = new DotenvEditor;
$editor->load(__DIR__.'/.env');
$editor->heading('Examples');
$editor->set('A', 't9maWr2GA6=');
$editor->set('B', 'this-should-be-$ingle-quoted');
$editor->set('C', 'multi
line
should be
quoted');
$editor->save();Results in
# Examples
A=t9maWr2GA6=
B=this-should-be-$ingle-quoted
C=multi
line
should be
quotedThis is not a valid dotenv file and, for example, Laravel will not be able to load it.
dotenv-editor/src/DotenvEditor.php
Line 155 in edf0a75
| ? sprintf('%s=%s', $key, $item) |
There needs to be some different preparation of values, that need quoting, prior to writing them to the .env file.
For example:
- If contains
=,#, or a$as part of variable/command substitution (e.g."$(bleh)"or"${FOO}") then wrap in double quotes - If contains
$not used for variable/command substitution, then wrap in single quotes - If contains new line character (
\n) either wrap in double quotes and\or convert the new line characters to a\nliteral string
Metadata
Metadata
Assignees
Labels
help wantedExtra attention is neededExtra attention is needed