Skip to content

[Dotenv] Quoting values with $ does not work as expected #26056

@mhujer

Description

@mhujer
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 4.0.4

When I have following values in .env:

PASSHASH1=$2y$10$kmIn2NJp1tUL0bALk.X/h.gjZ2b/6wQA72iYsa2PwpnRj544S/tPa
PASSHASH2='$2y$10$kmIn2NJp1tUL0bALk.X/h.gjZ2b/6wQA72iYsa2PwpnRj544S/tPa'
PASSHASH3="$2y$10$kmIn2NJp1tUL0bALk.X/h.gjZ2b/6wQA72iYsa2PwpnRj544S/tPa"

And I load them with this code:

<?php declare(strict_types = 1);

use Symfony\Component\Dotenv\Dotenv;

require_once 'vendor/autoload.php';

$dotenv = new Dotenv();
$dotenv->load(__DIR__.'/.env');

var_dump(getenv('PASSHASH1'));
var_dump(getenv('PASSHASH2'));
var_dump(getenv('PASSHASH3'));

The output is:

string(42) "$2y$10.X/h.gjZ2b/6wQA72iYsa2PwpnRj544S/tPa"
string(60) "$2y$10$kmIn2NJp1tUL0bALk.X/h.gjZ2b/6wQA72iYsa2PwpnRj544S/tPa"
string(42) "$2y$10.X/h.gjZ2b/6wQA72iYsa2PwpnRj544S/tPa"

The 1 and 3 are "broken". Only the variant quoted with ' works as expected. Quotes " are used in an example in documentation, so they should work as well. The non-quoted variant should throw an exception instead of silently changing the value.

I'm using PHP 7.1.12 + Windows 10, but the Dotenv uses PHP to parse the file, so it should not matter.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions