parse escaped quotes in unquoted env var values

This commit is contained in:
Christian Flothmann 2017-06-30 20:34:12 +02:00
parent 8b6cb57d87
commit 66a4fd749d
2 changed files with 7 additions and 0 deletions

View File

@ -215,6 +215,10 @@ final class Dotenv
$notQuoted = true;
$prevChr = $this->data[$this->cursor - 1];
while ($this->cursor < $this->end && "\n" !== $this->data[$this->cursor] && !((' ' === $prevChr || "\t" === $prevChr) && '#' === $this->data[$this->cursor])) {
if ('\\' === $this->data[$this->cursor] && isset($this->data[$this->cursor + 1]) && ('"' === $this->data[$this->cursor + 1] || "'" === $this->data[$this->cursor + 1])) {
++$this->cursor;
}
$value .= $prevChr = $this->data[$this->cursor];
++$this->cursor;
}

View File

@ -94,6 +94,9 @@ class DotenvTest extends TestCase
array('FOO=" "', array('FOO' => ' ')),
array('PATH="c:\\\\"', array('PATH' => 'c:\\')),
array("FOO=\"bar\nfoo\"", array('FOO' => "bar\nfoo")),
array('FOO=BAR\\"', array('FOO' => 'BAR"')),
array("FOO=BAR\\'BAZ", array('FOO' => "BAR'BAZ")),
array('FOO=\\"BAR', array('FOO' => '"BAR')),
// concatenated values