Cannot set path with spaces
I want to parametrise the path to a command-line tool:
C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe
... with this test script:
<?php
require __DIR__ . '/vendor/autoload.php';
$dotenv = new Dotenv\Dotenv(__DIR__);
$dotenv->load();
var_dump($_ENV['WKHTMLTOPDF']);
... and this expected output:
string(50) "C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
As of v2.2.0 it's apparently not possible:
WKHTMLTOPDF=C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe
... triggers:
Dotenv values containing spaces must be surrounded by quotes.
WKHTMLTOPDF="C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
.... prints:
string(52) ""C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe""
WKHTMLTOPDF='C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'
... prints:
string(52) "'C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe'"
Escaping spaces with \ (as in bash) triggers Dotenv values containing spaces must be surrounded by quotes as well.
Note: on Windows you can use short file names (if enabled) as a workaround:
WKHTMLTOPDF=C:\PROGRA~1\wkhtmltopdf\bin\wkhtmltopdf.exe
I cannot replicate. Using double quotes works.
Can you elaborate please?
Not much else, actually... I install phpdotenv as explained in readme:
D:\tmp\borrame>composer require vlucas/phpdotenv
Using version ^2.2 for vlucas/phpdotenv
./composer.json has been created
Loading composer repositories with package information
Updating dependencies (including require-dev)
- Installing vlucas/phpdotenv (v2.2.0)
Downloading: 100%
Writing lock file
Generating autoload files
D:\tmp\borrame>
... create an .env file and run the aforementioned PHP code with the described result (quotes themselves leaking into the final value).
I've ran my test script on several PHP versions (5.3, 5.5, 5.6 and 7.0) either on Windows and Linux, 32 and 64 bit—and it's 100% reproducible for me :-?
(*) Just fixed a typo:should be require __DIR__ . '/vendor/autoload.php'; (lowercase vendor) to work on Linux
I'm getting the same results as @kAlvaro
But I have a private key in my .env file. Example:
FIREBASE_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nBf9vq2t0oiQlYqF9FeVf+2FmGDt/XzZWzKBT7v1v961OsWfqzmMPRPKrta8CLd5k\nqMrx/HGcNo3purHVUZkEQVboeIxQYszfdWV300y+evr56fZVxD+WnDl1d4o9TbUe\nZC54ndkQBkziO//mE5Hbs56x1LkwBvTZd1LTsRN/Pe/HEqYQmF6rfEmvepgLTf/I\nGjpht8p+bfSrCipq/YcmCzGxGrVOftZQJAaKbRHnOZ1UUUgtJXuh7kxl+YZYR+4y\nzmmsfyhRjI1VmbQaUuUiU5m48Kl/kduzzMniLywQZ8xAStQMPnybVNrb7JWbg7Z2\npXKJX5f72Qvr5EDrxGImeOwCE9qXLH4b/1Q+XzjO0G6JK5gdDjWg1bowAMqqOzUe\n330Z+rjPSYvM79xvo2r9CnscmTyE9izjNXphcOPJReGfOFrsGGtCgR6FoGG+Q7dc\nrDUCggEBAIxlqgNCwk4rdWi0fmScRrlYuPSZhCl3Tt4P65ICQYX6HXN7KVq44x1M\nw+CmGdhQM+4YJ/cMYMdIIivnBgsVcL+nSaP+9ELLuPb6AFushsTcnhW+LZbw/Z6x\nQZcTSZqQYDbo/+KO/zRnkA38V2RnkA3TfWHc=\n-----END PRIVATE KEY-----\n"
(not a valid key, so you may want to test a valid key)
the surrounding quotes become part of the string, whether I use single quotes or double quotes
Seems we are all failing to understand something about this package. https://github.com/vlucas/phpdotenv/issues/133
To me, it makes no sense whatsoever to have to quote strings.
The only times I'd expect to use quotes would be ...
single_line_comment_prefix = "# "
trailing_spaces = "I need 2 spaces "
quoted_string = ""A quote""
And in all cases, the quotes are delimiters, not content.
It would be like saying every comma in a CSV file is part of the data elements it is used to separate.
But, I didn't write this library and clearly many of us are missing something obvious.
I'm also getting quoted strings on need-to-be-quoted-because-of-spaces strings. This forces me to trim these strings.
@GrahamCampbell Tested this a bit. Problem exists when a quoted value contains a \ character. Tested with v2.4.0 and PHP 7.0.12. There seems to be testcase for this so I do not know why it is not catched in Travis.
FOO="bar pop"
string(7) "bar pop"
FOO="bar \ pop"
string(11) ""bar \ pop""
@kAlvaro Since \ is used escaping character you can actually escape it with itself \\.
WKHTMLTOPDF="C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltoimage.exe"
string(50) "C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"
@tuupola Thank you, that syntax does work.
Is there any official documentation about the format? I was under the assumption that it followed Unix sh rules but it doesn't seem to be the case and perhaps that's the root of my misunderstanding.
I do not understand why this works:
WKHTMLTOPDF="\"\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe\"\""
Meanwhile, the values below do not work:
WKHTMLTOPDF="\"C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe\""
WKHTMLTOPDF="\"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe\""