From 1e726ec5266ea866968ae0f20388abb7b67e87d0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Cha=C5=82ubek?= Date: Wed, 21 Mar 2018 11:18:30 +0100 Subject: [PATCH] Fix empty named template (#9) * Add regression test for empty named template * Check for empty value when validation named templates --- src/Gin/Template/Template.php | 10 +++++++--- tests/Gin/Template/TemplateTest.php | 4 ++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/Gin/Template/Template.php b/src/Gin/Template/Template.php index 764886b..de344b7 100644 --- a/src/Gin/Template/Template.php +++ b/src/Gin/Template/Template.php @@ -139,9 +139,13 @@ public function isNamed() return false; } - // Return false if template is named, - // but name is bool or null. - if (isset($this->file[1]) && is_bool($this->file[1]) || null === $this->file[1]) { + // Return false if template is named, but name + // is invalid. A valid name should be: + if ( + isset($this->file[1]) && is_bool($this->file[1]) // should be set and not be a boolean + || null === $this->file[1] // or null value + || empty($this->file[1]) // or empty sting or array + ) { return false; } diff --git a/tests/Gin/Template/TemplateTest.php b/tests/Gin/Template/TemplateTest.php index e728db1..93193dd 100644 --- a/tests/Gin/Template/TemplateTest.php +++ b/tests/Gin/Template/TemplateTest.php @@ -108,6 +108,10 @@ public function it_should_return_no_named_filename_when_template_name_is_not_val $invalidNamedTemplate = $this->getTemplate($config, ['sample_template', null]); $this->assertFalse($invalidNamedTemplate->isNamed()); $this->assertEquals('sample_template.php', $invalidNamedTemplate->getFilename()); + + $invalidNamedTemplate = $this->getTemplate($config, ['sample_template', '']); + $this->assertFalse($invalidNamedTemplate->isNamed()); + $this->assertEquals('sample_template.php', $invalidNamedTemplate->getFilename()); } /**