Search code examples
symfonyescapingsymfony4dotenv

Symfony 4 Dotenv escape special characters


I use a password with a special char and symfony return an error "Malformed parameter "url"."

How can i use this kind of password ? foo?bar

I try with variables like that

DATABASE_USER='foo'
DATABASE_PASSWORD='foo?bar'
DATABASE_URL=mysql://${DATABASE_USER}:${DATABASE_PASSWORD}@100.100.100.100:3306/db

But is not working


Solution

  • as the variable name suggests, the DATABASE_URL has to be a URL. that is, everything that is a character with meaning in URLs (for example #, ?, :, ...) has to be URL-encoded.

    For example ? has to be encoded as %3F if it is supposed to appear in a different meaning than to mark the query. There are lots of tools online to URL-encode stuff...