From 217058b47561f2b7457a695ca61fc5c419383e46 Mon Sep 17 00:00:00 2001 From: Gerhard Seidel Date: Fri, 18 Oct 2019 13:11:49 +0200 Subject: [PATCH 1/3] [Routing] fix route loading with wildcard, but dir or file is empty --- .../Routing/Loader/Configurator/RoutingConfigurator.php | 3 ++- src/Symfony/Component/Routing/Loader/XmlFileLoader.php | 2 +- src/Symfony/Component/Routing/Loader/YamlFileLoader.php | 2 +- .../Tests/Fixtures/controller/empty_wildcard/.gitignore | 0 .../Tests/Fixtures/import_with_name_prefix/routing.yml | 4 ++++ 5 files changed, 8 insertions(+), 3 deletions(-) create mode 100644 src/Symfony/Component/Routing/Tests/Fixtures/controller/empty_wildcard/.gitignore diff --git a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php index a315cfb4ad..849db56759 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php @@ -39,7 +39,8 @@ class RoutingConfigurator final public function import($resource, $type = null, $ignoreErrors = false) { $this->loader->setCurrentDir(\dirname($this->path)); - $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file); + $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file) ?? []; + if (!\is_array($imported)) { return new ImportConfigurator($this->collection, $imported); } diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index ed4faf3915..7b5998bd20 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -169,7 +169,7 @@ class XmlFileLoader extends FileLoader $this->setCurrentDir(\dirname($path)); /** @var RouteCollection[] $imported */ - $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file); + $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file) ?? []; if (!\is_array($imported)) { $imported = [$imported]; diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index 15c223ecad..339776c13f 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -187,7 +187,7 @@ class YamlFileLoader extends FileLoader $this->setCurrentDir(\dirname($path)); - $imported = $this->import($config['resource'], $type, false, $file); + $imported = $this->import($config['resource'], $type, false, $file) ?? []; if (!\is_array($imported)) { $imported = [$imported]; diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/controller/empty_wildcard/.gitignore b/src/Symfony/Component/Routing/Tests/Fixtures/controller/empty_wildcard/.gitignore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/src/Symfony/Component/Routing/Tests/Fixtures/import_with_name_prefix/routing.yml b/src/Symfony/Component/Routing/Tests/Fixtures/import_with_name_prefix/routing.yml index 90dce0ea1b..057b7b2d6b 100644 --- a/src/Symfony/Component/Routing/Tests/Fixtures/import_with_name_prefix/routing.yml +++ b/src/Symfony/Component/Routing/Tests/Fixtures/import_with_name_prefix/routing.yml @@ -5,3 +5,7 @@ api: resource: ../controller/routing.yml name_prefix: api_ prefix: /api + +empty_wildcard: + resource: ../controller/empty_wildcard/* + prefix: /empty_wildcard From a54ecb0fae7ea9fbbf9bc9c6f5715d0ec235a9e5 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sat, 19 Oct 2019 15:04:41 +0200 Subject: [PATCH 2/3] bug #34024 [Routing] fix route loading with wildcard, but dir or file is empty (gseidel) This PR was merged into the 4.3 branch. Discussion ---------- [Routing] fix route loading with wildcard, but dir or file is empty | Q | A | ------------- | --- | Branch? | 4.3 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | no ticket i see so far | License | MIT In my route config i have something like: ```yaml empty_wildcard: resource: ../controller/empty_wildcard/* prefix: /empty_wildcard ``` But ``empty_wildcard`` is empty or has no route configured. So i had this error: ``Call to a member function addPrefix() on null`` This PR take care if no route is configured, there will be no error. Commits ------- 217058b475 [Routing] fix route loading with wildcard, but dir or file is empty --- .../Routing/Loader/Configurator/RoutingConfigurator.php | 3 ++- src/Symfony/Component/Routing/Loader/XmlFileLoader.php | 3 ++- src/Symfony/Component/Routing/Loader/YamlFileLoader.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php index 7614caea3d..d0cc02d1c3 100644 --- a/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php +++ b/src/Symfony/Component/Routing/Loader/Configurator/RoutingConfigurator.php @@ -39,7 +39,8 @@ class RoutingConfigurator final public function import($resource, $type = null, $ignoreErrors = false) { $this->loader->setCurrentDir(\dirname($this->path)); - $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file); + $imported = $this->loader->import($resource, $type, $ignoreErrors, $this->file) ?: []; + if (!\is_array($imported)) { return new ImportConfigurator($this->collection, $imported); } diff --git a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php index c114310fc3..29dfdb1665 100644 --- a/src/Symfony/Component/Routing/Loader/XmlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/XmlFileLoader.php @@ -146,7 +146,8 @@ class XmlFileLoader extends FileLoader $this->setCurrentDir(\dirname($path)); - $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file); + /** @var RouteCollection[] $imported */ + $imported = $this->import($resource, ('' !== $type ? $type : null), false, $file) ?: []; if (!\is_array($imported)) { $imported = [$imported]; diff --git a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php index bc21e9cb4d..568827695b 100644 --- a/src/Symfony/Component/Routing/Loader/YamlFileLoader.php +++ b/src/Symfony/Component/Routing/Loader/YamlFileLoader.php @@ -158,7 +158,7 @@ class YamlFileLoader extends FileLoader $this->setCurrentDir(\dirname($path)); - $imported = $this->import($config['resource'], $type, false, $file); + $imported = $this->import($config['resource'], $type, false, $file) ?: []; if (!\is_array($imported)) { $imported = [$imported]; From 4ad09ebafb1570878264aa49a73aab63c52a5aa2 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 20 Oct 2019 11:47:57 +0200 Subject: [PATCH 3/3] [HttpKernel] fix wrong removal of the just generated container dir --- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 325ef4d443..b05e877d7b 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -868,7 +868,7 @@ abstract class Kernel implements KernelInterface, RebootableInterface, Terminabl $fs->dumpFile($dir.$file, $code); @chmod($dir.$file, 0666 & ~umask()); } - $legacyFile = \dirname($dir.$file).'.legacy'; + $legacyFile = \dirname($dir.key($content)).'.legacy'; if (file_exists($legacyFile)) { @unlink($legacyFile); }