Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit a054d88

Browse filesBrowse files
committed
bug #34023 [Dotenv] allow LF in single-quoted strings (nicolas-grekas)
This PR was merged into the 3.4 branch. Discussion ---------- [Dotenv] allow LF in single-quoted strings | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - in a shell: ```sh FOO='bar baz' ``` is legal to set a value to (in PHP): ```php "bar\nbaz" ``` Commits ------- 4d79116 [Dotenv] allow LF in single-quoted strings
2 parents 52f8fc8 + 4d79116 commit a054d88
Copy full SHA for a054d88

File tree

2 files changed

+10
-15
lines changed
Filter options

2 files changed

+10
-15
lines changed

‎src/Symfony/Component/Dotenv/Dotenv.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Dotenv.php
+8-15Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -189,25 +189,18 @@ private function lexValue()
189189

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

195-
while ("\n" !== $this->data[$this->cursor]) {
196-
if ("'" === $this->data[$this->cursor]) {
197-
break;
198-
}
199-
$value .= $this->data[$this->cursor];
200-
++$this->cursor;
194+
do {
195+
if ($this->cursor + ++$len === $this->end) {
196+
$this->cursor += $len;
201197

202-
if ($this->cursor === $this->end) {
203198
throw $this->createFormatException('Missing quote to end the value');
204199
}
205-
}
206-
if ("\n" === $this->data[$this->cursor]) {
207-
throw $this->createFormatException('Missing quote to end the value');
208-
}
209-
++$this->cursor;
210-
$v .= $value;
200+
} while ("'" !== $this->data[$this->cursor + $len]);
201+
202+
$v .= substr($this->data, 1 + $this->cursor, $len - 1);
203+
$this->cursor += 1 + $len;
211204
} elseif ('"' === $this->data[$this->cursor]) {
212205
$value = '';
213206
++$this->cursor;

‎src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Dotenv/Tests/DotenvTest.php
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +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 9"],
4344
['export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"],
4445
['FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"],
4546
];
@@ -105,6 +106,7 @@ public function getEnvData()
105106
['FOO="bar\rfoo"', ['FOO' => "bar\rfoo"]],
106107
['FOO=\'bar\nfoo\'', ['FOO' => 'bar\nfoo']],
107108
['FOO=\'bar\rfoo\'', ['FOO' => 'bar\rfoo']],
109+
["FOO='bar\nfoo'", ['FOO' => "bar\nfoo"]],
108110
['FOO=" FOO "', ['FOO' => ' FOO ']],
109111
['FOO=" "', ['FOO' => ' ']],
110112
['PATH="c:\\\\"', ['PATH' => 'c:\\']],

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.