8000 [DI] Strip New Lines and Whitespace for multi-line XML Parameters for Class Initialization by kylecannon · Pull Request #6123 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Strip New Lines and Whitespace for multi-line XML Parameters for Class Initialization #6123

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 4 commits 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
Original file line number Diff line number Diff line change
Expand Up @@ -759,8 +759,8 @@ private function createService(Definition $definition, $id)

$service = call_user_func_array(array($factory, $definition->getFactoryMethod()), $arguments);
} else {
$r = new \ReflectionClass($parameterBag->resolveValue($definition->getClass()));

$r = new \ReflectionClass(trim($parameterBag->resolveValue($definition->getClass())));
$service = null === $r->getConstructor() ? $r->newInstance() : $r->newInstanceArgs($arguments);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,70 @@ public function testCreateServiceConfigurator()
}
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateServiceWithNewLineWrapping()
{
$builder = new ContainerBuilder();
$builder->setParameter('foo1class', "\nFooClass\n");
$builder->register('foo1', '%foo1class%')->setFile(__DIR__ . '/Fixtures/includes/foo.php');
try {
$this->assertInstanceOf(
'\FooClass',
$builder->get('foo1'),
'New Line Wrapping \n in Parameter should be stripped out.'
);
} catch (\ReflectionException $e) {
$this->fail('FooClass is not callable due to the new lines not being stripped');
}
$builder->setParameter('foo2class', "\rFooClass\r");
$builder->register('foo2', '%foo2class%')->setFile(__DIR__ . '/Fixtures/includes/foo.php');
try {
$this->assertInstanceOf(
'\FooClass',
$builder->get('foo2'),
'New Line Wrapping \r in Parameter should be stripped out.'
);
} catch (\ReflectionException $e) {
$this->fail('FooClass is not callable due to the new lines not being stripped');
}
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::createService
*/
public function testCreateServiceWithNewLineWrappingWithWhiteSpace()
{
$builder = new ContainerBuilder();
$builder->setParameter('foo1class', "\n FooClass \n");
$builder->register('foo1', '%foo1class%')->setFile(__DIR__ . '/Fixtures/includes/foo.php');
try {
$this->assertInstanceOf(
'\FooClass',
$builder->get('foo1'),
'New Line Wrapping \n in Parameter should be stripped out along with whitespace.'
);
} catch (\ReflectionException $e) {
$this->fail(
'FooClass is not callable due to the new lines not being stripped and/or whitespacing not being trimmed'
);
}
$builder->setParameter('foo2class', "\r FooClass \r");
$builder->register('foo2', '%foo2class%')->setFile(__DIR__ . '/Fixtures/includes/foo.php');
try {
$this->assertInstanceOf(
'\FooClass',
$builder->get('foo2'),
'New Line Wrapping \r in Parameter should be stripped out along with whitespace.'
);
} catch (\ReflectionException $e) {
$this->fail(
'FooClass is not callable due to the new lines not being stripped and/or whitespacing not being trimmed.'
);
}
}

/**
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::resolveServices
*/
Expand Down
0