diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-08-12 12:19:24 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-08-12 12:19:24 +0200 |
commit | abd3d5c6a5803827e54f769e5677cdfa7ea4350b (patch) | |
tree | 00adbc69ad9460af69f23044d14ee8773eb4a7f5 | |
parent | 33727131ac05e254d467f3fdb438772f69f25362 (diff) | |
parent | 182bc17aebe19f49c30f50aacabdb1c9824c6f68 (diff) | |
download | nextcloud-server-abd3d5c6a5803827e54f769e5677cdfa7ea4350b.tar.gz nextcloud-server-abd3d5c6a5803827e54f769e5677cdfa7ea4350b.zip |
Merge pull request #17982 from owncloud/appframework-sanitize-name
Sanitize class names before registerService/query
-rw-r--r-- | lib/private/appframework/utility/simplecontainer.php | 10 | ||||
-rw-r--r-- | tests/lib/appframework/utility/SimpleContainerTest.php | 19 |
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/private/appframework/utility/simplecontainer.php b/lib/private/appframework/utility/simplecontainer.php index efe1b0812a6..83a08acde26 100644 --- a/lib/private/appframework/utility/simplecontainer.php +++ b/lib/private/appframework/utility/simplecontainer.php @@ -99,6 +99,7 @@ class SimpleContainer extends Container implements IContainer { * @throws QueryException if the query could not be resolved */ public function query($name) { + $name = $this->sanitizeName($name); if ($this->offsetExists($name)) { return $this->offsetGet($name); } else { @@ -128,6 +129,7 @@ class SimpleContainer extends Container implements IContainer { * @param bool $shared */ public function registerService($name, Closure $closure, $shared = true) { + $name = $this->sanitizeName($name); if (isset($this[$name])) { unset($this[$name]); } @@ -151,4 +153,12 @@ class SimpleContainer extends Container implements IContainer { }, false); } + /* + * @param string $name + * @return string + */ + protected function sanitizeName($name) { + return ltrim($name, '\\'); + } + } diff --git a/tests/lib/appframework/utility/SimpleContainerTest.php b/tests/lib/appframework/utility/SimpleContainerTest.php index 8217749aed4..e21e0ca13f2 100644 --- a/tests/lib/appframework/utility/SimpleContainerTest.php +++ b/tests/lib/appframework/utility/SimpleContainerTest.php @@ -170,6 +170,25 @@ class SimpleContainerTest extends \Test\TestCase { $this->container->query('test'), $this->container->query('test1')); } + public function sanitizeNameProvider() { + return [ + ['ABC\\Foo', 'ABC\\Foo'], + ['\\ABC\\Foo', '\\ABC\\Foo'], + ['\\ABC\\Foo', 'ABC\\Foo'], + ['ABC\\Foo', '\\ABC\\Foo'], + ]; + } + + /** + * @dataProvider sanitizeNameProvider + */ + public function testSanitizeName($register, $query) { + $this->container->registerService($register, function() { + return 'abc'; + }); + $this->assertEquals('abc', $this->container->query($query)); + } + /** * @expectedException \OCP\AppFramework\QueryException */ |