Ignore comments at the end of line
If the variable value had no quotes a comment at the end of the line was added to the variable. Spaces between text and comment mark will be removed too Old: FOO=Test # Comment -> $_ENV['FOO'] = "Test # Comment" New: FOO=Test # Comment -> $_ENV['FOO'] = "Test"
This commit is contained in:
@@ -6,6 +6,9 @@ namespace gullevek\dotEnv;
|
||||
|
||||
class DotEnv
|
||||
{
|
||||
/** @var string constant comment char, set to # */
|
||||
private const COMMENT_CHAR = '#';
|
||||
|
||||
/**
|
||||
* parses .env file
|
||||
*
|
||||
@@ -72,6 +75,11 @@ class DotEnv
|
||||
// add removed new line back because this is a multi line
|
||||
$value = ltrim($value, '"') . PHP_EOL;
|
||||
}
|
||||
} else {
|
||||
// strip any quotes at end for unquoted single line
|
||||
// an right hand spaces are removed too
|
||||
$value = false !== ($pos = strpos($value, self::COMMENT_CHAR)) ?
|
||||
rtrim(substr($value, 0, $pos)) : $value;
|
||||
}
|
||||
// if block is set, we strip line of slashes
|
||||
$_ENV[$var] = $block === true ? stripslashes($value) : $value;
|
||||
@@ -95,5 +103,4 @@ class DotEnv
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// __END__
|
||||
|
||||
Reference in New Issue
Block a user