Skip to content
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

fatal error when using database password with two % #61

Closed
fritzmg opened this issue Jul 10, 2017 · 20 comments
Closed

fatal error when using database password with two % #61

fritzmg opened this issue Jul 10, 2017 · 20 comments
Assignees
Labels

Comments

@fritzmg
Copy link
Contributor

fritzmg commented Jul 10, 2017

Reproduction

  1. Set the password of your MySQL database user to asd%asd%asd for example.
  2. Install the Contao Managed Edition and open the Install Tool
  3. Fill in the credentials of your database user and save.

The following fatal error will occur:

Fatal error: Uncaught Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException: You have requested a non-existent parameter "asd". 
in …\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php:100 Stack trace:
#0 …\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag.php(56): Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->get('asd') #1 …\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php(232): Symfony\Component\DependencyInjection\ParameterBag\EnvPlaceholderParameterBag->get('asd')
#2 [internal function]: Symfony\Component\DependencyInjection\ParameterBag\ParameterBag->Symfony\Component\DependencyInjection\ParameterBag\{closure}(Array)
#3 …\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php(242): preg_replace_callback('/%%|%([^%\\s]+ 
in …\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag.php on line 100

Cause

The Install Tool creates the following parameters.yml:

parameters:
    database_password: asd%asd%asd

If any of your Symfony parameters contain two %, you need to escape them. This will work:

parameters:
    database_password: asd%%asd%%asd

According to https://stackoverflow.com/a/27274304/374996 using double quotes should also work, but I cannot confirm that. The error still occurs when using "asd%asd%asd".

@Toflar
Copy link
Member

Toflar commented Jul 10, 2017

It should be single quoted. So

database_password: 'asd%asd%asd'

can you check that, pls? :)
Afaik unquoted strings will be (or are already?) deprecated anyway.

@fritzmg
Copy link
Contributor Author

fritzmg commented Jul 10, 2017

Afaik unquoted strings will be (or are already?) deprecated anyway.

Hmm, this article only says

In Symfony 3.1, the usage of % at the beginning of an unquoted string is deprecated and it will be removed in Symfony 4.0.

But in this case, the % is not at the beginning of the unquoted string.

Using database_password: 'asd%asd%asd' also does not work. Another user confirmed that here also.

@dmolineus
Copy link

dmolineus commented Jul 10, 2017

Every "%" has to be escaped with a second one no matter if it's at the beginning of not. See http://symfony.com/doc/current/service_container/parameters.html#parameters-in-configuration-files

"If you use a string that starts with @ or has % anywhere in it, you need to escape it by adding another @ or %:"

@leofeyer
Copy link
Member

Fixed in 9bd4ea0.

@Toflar
Copy link
Member

Toflar commented Jul 11, 2017

Same should be done for @!

@leofeyer
Copy link
Member

I wonder why the Sf parameter dumper does not do this by default? It also does not add any quotes.

@leofeyer
Copy link
Member

Strings containing any of the following characters must be quoted. Although you can use double quotes, for these characters it is more convenient to use single quotes, which avoids having to escape any backslash \:

  • :, {, }, [, ], ,, &, *, #, ?, |, -, <, >, =, !, %, @, `````

If the string contains any of the following control characters, it must be escaped with double quotes:

  • \0, \x01, \x02, \x03, \x04, \x05, \x06, \a, \b, \t, \n, \v, \f, \r, \x0e, \x0f, \x10, \x11, \x12, \x13, \x14, \x15, \x16, \x17, \x18, \x19, \x1a, \e, \x1c, \x1d, \x1e, \x1f, \N, \_, \L, \P

Are we supposed to check this ourselves?

@Toflar
Copy link
Member

Toflar commented Jul 11, 2017

Where did you get that info from?

@leofeyer
Copy link
Member

@leofeyer
Copy link
Member

leofeyer commented Jul 11, 2017

There is an Escaper class, which however does not handle % and @.

@Toflar
Copy link
Member

Toflar commented Jul 11, 2017

@leofeyer
Copy link
Member

symfony/symfony#23474

@stof
Copy link

stof commented Jul 11, 2017

The escaping of % by doubling them has nothing to do with the YAML component. It is not a YAML escaping. It is a Symfony DI escaping (because % is used there to represent the usage of parameters).
If you dump a YAML file which will be parse to configure the DI component, you need to account for several escaping: the content sent to the YAML dumper needs to contain the necessary DI escaping (the YAML dumper won't do it, as it knows nothing about DI).

@stof
Copy link

stof commented Jul 11, 2017

Btw, the YAML way of escaping the % at the beginning of a value is to quote the value. But this won't escape things for DI at all, as the YAML parsing will still give you a single %

@leofeyer
Copy link
Member

Thanks @stof for shedding some light on this.

@leofeyer
Copy link
Member

Fixed in 263af55 now.

@Toflar
Copy link
Member

Toflar commented Jul 11, 2017

Thanks @stof! Makes sense! I still think the fix is wrong, though :-) There's a DependencyInjection/Dumper/YamlDumper which handles escaping itself: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/DependencyInjection/Dumper/YamlDumper.php#L342

@stof
Copy link

stof commented Jul 11, 2017

@Toflar you could use this dumper to dump a ContainerBuilder in which you would have added the parameters. But I'm not sure it would work that well.

Btw, inside a parameter, you don't need to double the initial @ (it has a special meaning only in arguments in the YAML format, not in parameters)

@Toflar
Copy link
Member

Toflar commented Jul 11, 2017

Ah true, thanks for your comments - highly appreciated :)

@leofeyer
Copy link
Member

Btw, inside a parameter, you don't need to double the initial @

Removed in 7ce8feb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants