ErrorException on multiline value
When reading the file, I see an error on multiline values.
Example:
OAUTH_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----
ABCDefBADAnbgkqhkiG9w0BAQEFAASCCSwwggkoAgEAAoICAQZCdZMQwLW9ytam
ny5xRMdXMWEPZnQ+hHmi7E4/qiVkXv+BB3iXmY60OLg438Z10sBN7bFr71m4RwOw
Error:
ErrorException
Undefined array key 1
at vendor/mirazmac/dotenvwriter/src/Writer.php:235
$lines = preg_split('/\r\n|\r|\n/', $this->content);
foreach ($lines as $line) {
if (mb_strlen(trim($line)) && !(mb_strpos(trim($line), '#') === 0)) {
[$key, $value] = explode('=', (string) $line);
$this->variables[$key] = $this->formatValue($value);
}
}
}
First iteration could be to just ignore them in the parse function with an ignoreInvalidLines flag to at least not throw on read and just not support that usecase. But still those lines would needed to be preserved on the output file.
Correct me if I'm wrong but I don't think .env supports multiline values?
We use this .env in a laravel project and env('OAUTH_PRIVATE_KEY') shows the multiline key properly. Apart from that I also have not seen it multilined in other places before, so I am not sure if its worth investigating. I have a very specific usecase and can do it a different way without this lib. Just wanted to note down what I found :-)
What about a multi-line-support-mode?
+1 on this.
Also have private key data on .env for OAUTH and Laravel works with it perfectly.
Opened a PR to fix this. Would be great if this could be merged and a new version deployed, @MirazMac
I thought about a mode, where the user needs to enable the multi-line support. Enable it by default .. I'm not sure about that
@basteyy It's simpler just to check for open and unclosed quotes than having people go through documentation to understand there's a mode setting to do that. If there's an unclosed quote the .env should fail parsing on other packages as well. At least that's my pov
Should be fixed by #7 please upgrade to 0.6