Skip to content

[Dotenv] properly parse backslashes in unquoted env vars #29222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 24, 2018

Conversation

xabbuh
Copy link
Member

@xabbuh xabbuh commented Nov 14, 2018

Q A
Branch? 3.4
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #29202
License MIT
Doc PR

@@ -246,7 +246,7 @@ private function lexValue()

++$this->cursor;
}
$value = rtrim($value);
$value = str_replace('\\\\', '\\', rtrim($value));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure that's enough: eg FOO=A\\$B should resolve to A\Foo when B=Foo is set previoulsy.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you are right, and this also didn't work with double-quoted strings, both cases should be good now

@@ -350,7 +352,7 @@ private function resolveVariables($value)
}

$regex = '/
(\\\\)? # escaped with a backslash?
((?:\\\\)?\\\\)? # escaped with a backslash?
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it this will probably not be enough as there could be an endless number of backslashes and we need to check whether we have an even or an odd number of them to decide whether or not the $ character is escaped.

@xabbuh xabbuh force-pushed the issue-29202 branch 2 times, most recently from cd30eb9 to d418826 Compare November 14, 2018 19:06
Copy link
Contributor

@OskarStark OskarStark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work 👌🏻

@fabpot
Copy link
Member

fabpot commented Nov 24, 2018

Thank you @xabbuh.

@fabpot fabpot merged commit 785fff5 into symfony:3.4 Nov 24, 2018
fabpot added a commit that referenced this pull request Nov 24, 2018
…xabbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Dotenv] properly parse backslashes in unquoted env vars

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29202
| License       | MIT
| Doc PR        |

Commits
-------

785fff5 properly parse backslashes in unquoted env vars
@xabbuh xabbuh deleted the issue-29202 branch November 24, 2018 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants