-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[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
Conversation
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)); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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? |
There was a problem hiding this comment.
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.
cd30eb9
to
d418826
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great work 👌🏻
Thank you @xabbuh. |
…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