[Dotenv] allow LF in single-quoted strings
This commit is contained in:
parent
29cabf94c5
commit
4d79116a0d
@ -189,25 +189,18 @@ final class Dotenv
|
|||||||
|
|
||||||
do {
|
do {
|
||||||
if ("'" === $this->data[$this->cursor]) {
|
if ("'" === $this->data[$this->cursor]) {
|
||||||
$value = '';
|
$len = 0;
|
||||||
++$this->cursor;
|
|
||||||
|
|
||||||
while ("\n" !== $this->data[$this->cursor]) {
|
do {
|
||||||
if ("'" === $this->data[$this->cursor]) {
|
if ($this->cursor + ++$len === $this->end) {
|
||||||
break;
|
$this->cursor += $len;
|
||||||
}
|
|
||||||
$value .= $this->data[$this->cursor];
|
|
||||||
++$this->cursor;
|
|
||||||
|
|
||||||
if ($this->cursor === $this->end) {
|
|
||||||
throw $this->createFormatException('Missing quote to end the value');
|
throw $this->createFormatException('Missing quote to end the value');
|
||||||
}
|
}
|
||||||
}
|
} while ("'" !== $this->data[$this->cursor + $len]);
|
||||||
if ("\n" === $this->data[$this->cursor]) {
|
|
||||||
throw $this->createFormatException('Missing quote to end the value');
|
$v .= substr($this->data, 1 + $this->cursor, $len - 1);
|
||||||
}
|
$this->cursor += 1 + $len;
|
||||||
++$this->cursor;
|
|
||||||
$v .= $value;
|
|
||||||
} elseif ('"' === $this->data[$this->cursor]) {
|
} elseif ('"' === $this->data[$this->cursor]) {
|
||||||
$value = '';
|
$value = '';
|
||||||
++$this->cursor;
|
++$this->cursor;
|
||||||
|
@ -40,6 +40,7 @@ class DotenvTest extends TestCase
|
|||||||
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
|
['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', "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"],
|
['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"],
|
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
|
||||||
];
|
];
|
||||||
@ -105,6 +106,7 @@ class DotenvTest extends TestCase
|
|||||||
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
|
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
|
||||||
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
|
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
|
||||||
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
|
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
|
||||||
|
["FOO='bar\nfoo'", ['FOO' => "bar\nfoo"]],
|
||||||
['FOO=" FOO "', ['FOO' => ' FOO ']],
|
['FOO=" FOO "', ['FOO' => ' FOO ']],
|
||||||
['FOO=" "', ['FOO' => ' ']],
|
['FOO=" "', ['FOO' => ' ']],
|
||||||
['PATH="c:\\\\"', ['PATH' => 'c:\\']],
|
['PATH="c:\\\\"', ['PATH' => 'c:\\']],
|
||||||
|
Reference in New Issue
Block a user