Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

[DI] ContainerBuilder can throw when resolving unescaped parameters #59594

Copy link
Copy link
Open
@MatTheCat

Description

@MatTheCat
Issue body actions

Symfony version(s) affected

≥ 3.3.7

Description

When ContainerBuilder::compile is called with $resolveEnvPlaceholders, it will end up creating a new ParameterBag from the old one:

if ($resolveEnvPlaceholders) {
$this->parameterBag = new ParameterBag($this->resolveEnvPlaceholders($bag->all(), true));
}

With true as its second parameter, resolveEnvPlaceholders will start by calling the bag’s resolveValue method:

if (true === $format ??= '%%env(%s)%%') {
$value = $bag->resolveValue($value);
}

Problem is, at this point the parameter bag already has been resolved by the ResolveParameterPlaceHoldersPass, which means parameters’ value have been unescaped:

$parameters[$key] = $this->unescapeValue($value);

Since unescaped parameters can appear as if they contain a placeholder, those will trigger a ParameterNotFoundException.

How to reproduce

$builder = new ContainerBuilder();
$builder->setParameter('foo', '%%bar%%');
$builder->compile(true);

Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException: You have requested a non-existent parameter "bar".

Possible Solution

I guess an easy fix would be to ignore ParameterNotFoundExceptions when creating the new ParameterBag? It feels like addressing a symptom rather than a cause though.

Additional Context

Spotted while investigating #59028.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.