Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Dotenv] allow LF in single-quoted strings #34023

Merged
merged 1 commit into from Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 8 additions & 15 deletions src/Symfony/Component/Dotenv/Dotenv.php
Expand Up @@ -189,25 +189,18 @@ private function lexValue()

do {
if ("'" === $this->data[$this->cursor]) {
$value = '';
++$this->cursor;
$len = 0;

while ("\n" !== $this->data[$this->cursor]) {
if ("'" === $this->data[$this->cursor]) {
break;
}
$value .= $this->data[$this->cursor];
++$this->cursor;
do {
if ($this->cursor + ++$len === $this->end) {
$this->cursor += $len;

if ($this->cursor === $this->end) {
throw $this->createFormatException('Missing quote to end the value');
}
}
if ("\n" === $this->data[$this->cursor]) {
throw $this->createFormatException('Missing quote to end the value');
}
++$this->cursor;
$v .= $value;
} while ("'" !== $this->data[$this->cursor + $len]);

$v .= substr($this->data, 1 + $this->cursor, $len - 1);
$this->cursor += 1 + $len;
} elseif ('"' === $this->data[$this->cursor]) {
$value = '';
++$this->cursor;
Expand Down
2 changes: 2 additions & 0 deletions src/Symfony/Component/Dotenv/Tests/DotenvTest.php
Expand Up @@ -40,6 +40,7 @@ public function getEnvDataWithFormatErrors()
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 9"],
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
];
Expand Down Expand Up @@ -105,6 +106,7 @@ public function getEnvData()
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
["FOO='bar\nfoo'", ['FOO' => "bar\nfoo"]],
['FOO=" FOO "', ['FOO' => ' FOO ']],
['FOO=" "', ['FOO' => ' ']],
['PATH="c:\\\\"', ['PATH' => 'c:\\']],
Expand Down