Skip to content

updated Parser class to support escaping $sign - #377

Closed
rsalimian wants to merge 1 commit into
phpdotenv:masterfrom
rsalimian:master
Closed

rsalimian wants to merge 1 commit into
phpdotenv:masterfrom
rsalimian:master

Conversation

@rsalimian

Copy link
Copy Markdown

Parser raises a fatal error if env value contains a dollar sign escaping like '3mypas$word'.
added the dollar sign to escaping list at the case ESCAPE_STATE fixed the issue.

Fatal error: Uncaught Dotenv\Exception\InvalidFileException: Failed to parse dotenv file due to an unexpected escape sequence. Failed at ['3mypas\$word'].

…ues like MY_PASSWORD='3Pas$wdocker image history 45'
@GrahamCampbell

Copy link
Copy Markdown
Collaborator

Does it not already parse properly without the slash?

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

added the dollar sign to escaping list at the case ESCAPE_STATE fixed the issue.

That addition looks incorrect, and won't stop it being treated like a variable, actually.

@rsalimian

Copy link
Copy Markdown
Author

with single quotes should not treat as a variable and just as plain text.

it parses when you set like myVAR=3mypas$word, but raises that error when explicitly
set like myVAR='3mypas$word'.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

with single quotes should not treat as a variable and just as plain text.

No, the variable replacement system doesn't care about the quotes you use. It is not like PHP strings.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

Resolving of nested variables is done after parsing, so adding an escape sequence, even in principle, won't work.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

Simply never try to escape dollars, and you will always get the string literal you want. I'm going to open a new issue to address if we want to forbid variable evaluation in single quoted strings and/or add a way to prevent variable evaluation from happening.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

This would be a breaking change though, so would require a new major version.

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

#378

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

NB, the way docker escape dollars is with a double dollar sign. Maybe that is the way to go?

@GrahamCampbell

Copy link
Copy Markdown
Collaborator

@rsalimian BTW, phpdotenv only actually expands environment variables that are quoted, so you should definitely write: '3mypas$word' and that will work correctly, both in v3 and the upcoming v4 version (with the changes from #380).

@rsalimian

Copy link
Copy Markdown
Author

thank you for having it in V4 RFC.
I don't have control to set it like 3mypas$word.

this is my scenario is, in docker stack service definition
I use the export command to save the environment to a .env. so the Export command is doing the escape stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants