Navigation Menu

Skip to content

Commit

Permalink
bug #23342 [Dotenv] parse escaped quotes in unquoted env var values (…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
fabpot committed Jul 3, 2017
2 parents 1b0e920 + 66a4fd7 commit bfd4173
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Symfony/Component/Dotenv/Dotenv.php
Expand Up @@ -215,6 +215,10 @@ private function lexValue()
$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;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Symfony/Component/Dotenv/Tests/DotenvTest.php
Expand Up @@ -94,6 +94,9 @@ public function getEnvData()
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

Expand Down

0 comments on commit bfd4173

Please sign in to comment.