Skip to content

[DependencyInjection] Fixed unescaping of class arguments #4707

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/Symfony/Component/DependencyInjection/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ CHANGELOG
* added Definition::clearTag()
* component exceptions that inherit base SPL classes are now used exclusively
(this includes dumped containers)
* fixed unescaping of class arguments, method ParameterBag::unescapeValue() was made
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you prepend "[BC BREAK]" please ?

public

Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,11 @@ private function createService(Definition $definition, $id)
require_once $this->getParameterBag()->resolveValue($definition->getFile());
}

$arguments = $this->resolveServices($this->getParameterBag()->resolveValue($definition->getArguments()));
$arguments = $this->resolveServices(
$this->getParameterBag()->unescapeValue(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may be it's worth adding a local variable $parameterBag as it is used quite a lot in the method

$this->getParameterBag()->resolveValue($definition->getArguments())
)
);

if (null !== $definition->getFactoryMethod()) {
if (null !== $definition->getFactoryClass()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function escapeValue($value)
return $value;
}

private function unescapeValue($value)
public function unescapeValue($value)
{
if (is_string($value)) {
return str_replace('%%', '%', $value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,13 @@ function resolveValue($value);
* @return mixed
*/
function escapeValue($value);

/**
* Unescape parameter placeholders %
*
* @param mixed $value
*
* @return mixed
*/
function unescapeValue($value);
}
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ public function testCreateServiceArguments()
{
$builder = new ContainerBuilder();
$builder->register('bar', 'stdClass');
$builder->register('foo1', 'FooClass')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar')));
$builder->register('foo1', 'FooClass')->addArgument(array('foo' => '%value%', '%value%' => 'foo', new Reference('bar'), '%%unescape_it%%'));
$builder->setParameter('value', 'bar');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar')), $builder->get('foo1')->arguments, '->createService() replaces parameters and service references in the arguments provided by the service definition');
$this->assertEquals(array('foo' => 'bar', 'bar' => 'foo', $builder->get('bar'), '%unescape_it%'), $builder->get('foo1')->arguments, '->createService() replaces parameters and service references in the arguments provided by the service definition');
}

/**
Expand Down