bug #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
-------

66a4fd749d parse escaped quotes in unquoted env var values
This commit is contained in:
Fabien Potencier 2017-07-03 09:56:41 +03:00
commit bfd4173860
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