Skip to content

Commit bfd4173

Browse files
committed
bug symfony#23342 [Dotenv] parse escaped quotes in unquoted env var values (xabbuh)
This PR was merged into the 3.3 branch. Discussion ---------- [Dotenv] parse escaped quotes in unquoted env var values | Q | A | ------------- | --- | Branch? | 3.3 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | | License | MIT | Doc PR | Commits ------- 66a4fd7 parse escaped quotes in unquoted env var values
2 parents 1b0e920 + 66a4fd7 commit bfd4173

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,10 @@ private function lexValue()
215215
$notQuoted = true;
216216
$prevChr = $this->data[$this->cursor - 1];
217217
while ($this->cursor < $this->end && "\n" !== $this->data[$this->cursor] && !((' ' === $prevChr || "\t" === $prevChr) && '#' === $this->data[$this->cursor])) {
218+
if ('\\' === $this->data[$this->cursor] && isset($this->data[$this->cursor + 1]) && ('"' === $this->data[$this->cursor + 1] || "'" === $this->data[$this->cursor + 1])) {
219+
++$this->cursor;
220+
}
221+
218222
$value .= $prevChr = $this->data[$this->cursor];
219223
++$this->cursor;
220224
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ public function getEnvData()
9494
array('FOO=" "', array('FOO' => ' ')),
9595
array('PATH="c:\\\\"', array('PATH' => 'c:\\')),
9696
array("FOO=\"bar\nfoo\"", array('FOO' => "bar\nfoo")),
97+
array('FOO=BAR\\"', array('FOO' => 'BAR"')),
98+
array("FOO=BAR\\'BAZ", array('FOO' => "BAR'BAZ")),
99+
array('FOO=\\"BAR', array('FOO' => '"BAR')),
97100

98101
// concatenated values
99102

0 commit comments

Comments
 (0)