You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't escape single quotes in single quote string #442
If I have a value (using the bash way to "escape" a single quote in a single quote string):
BLARG='hey'\''string'
I get the following error:
Fatal error: Uncaught Dotenv\Exception\InvalidFileException: Failed to parse dotenv file due to unexpected whitespace. Failed at ['hey'\''string']. in /var/www/html/vendor/vlucas/phpdotenv/src/Loader/Parser.php on line 119
Even if I try this, which doesn't work in bash, but would be more in line with double quotes I still get an error:
BLARG='hey\'string'
One or the other should be supported. Preferably the former as it's more inline with bash interpretation of env vars, so the same env file can be used by bash scripts and php.
I'm using single quotes to avoid interpolation by double quotes.
Activity
GrahamCampbell commentedon May 25, 2020
Yep, this is correct. Single quote strings do not accept escape characters, in line with what bash does. See https://linuxhint.com/bash_escape_quotes/.
GrahamCampbell commentedon May 25, 2020
You can avoid interpolation by escaping the dollars signs in double quote mode. See https://github.com/vlucas/phpdotenv/blob/v4.1.6/tests/fixtures/env/nested.env and https://github.com/vlucas/phpdotenv/blob/v4.1.6/tests/Dotenv/DotenvTest.php#L180-L197 for examples of how this works. In particular, look at
NVAR4andNVAR15. :)GrahamCampbell commentedon May 25, 2020
NB This has been available in version 4.0.0, implemented in #380.