Skip to content

Commit 62d93bf

Browse files
Merge branch '3.4' into 4.3
* 3.4: [Dotenv] allow LF in single-quoted strings [Yaml] Throw exception for tagged invalid inline elements
2 parents f8b4f43 + c7e8e47 commit 62d93bf

File tree

2 files changed

+10
-16
lines changed

2 files changed

+10
-16
lines changed

Dotenv.php

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -263,25 +263,18 @@ private function lexValue()
263263

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

269-
while ("\n" !== $this->data[$this->cursor]) {
270-
if ("'" === $this->data[$this->cursor]) {
271-
break;
272-
}
273-
$value .= $this->data[$this->cursor];
274-
++$this->cursor;
268+
do {
269+
if ($this->cursor + ++$len === $this->end) {
270+
$this->cursor += $len;
275271

276-
if ($this->cursor === $this->end) {
277272
throw $this->createFormatException('Missing quote to end the value');
278273
}
279-
}
280-
if ("\n" === $this->data[$this->cursor]) {
281-
throw $this->createFormatException('Missing quote to end the value');
282-
}
283-
++$this->cursor;
284-
$v .= $value;
274+
} while ("'" !== $this->data[$this->cursor + $len]);
275+
276+
$v .= substr($this->data, 1 + $this->cursor, $len - 1);
277+
$this->cursor += 1 + $len;
285278
} elseif ('"' === $this->data[$this->cursor]) {
286279
$value = '';
287280
++$this->cursor;

Tests/DotenvTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public function getEnvDataWithFormatErrors()
4040
['FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"],
4141
['FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"],
4242
['FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"],
43-
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"],
43+
['FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 9"],
4444
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
4545
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
4646
['FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"],
@@ -112,6 +112,7 @@ public function getEnvData()
112112
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
113113
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
114114
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
115+
["FOO='bar\nfoo'", ['FOO' => "bar\nfoo"]],
115116
['FOO=" FOO "', ['FOO' => ' FOO ']],
116117
['FOO=" "', ['FOO' => ' ']],
117118
['PATH="c:\\\\"', ['PATH' => 'c:\\']],

0 commit comments

Comments
 (0)