Эх сурвалжийг харах

Add validation to prevent empty template_class_prefix.

Fixes #298
Justin Hileman 8 жил өмнө
parent
commit
55e6ac81ba

+ 4 - 0
src/Mustache/Engine.php

@@ -142,6 +142,10 @@ class Mustache_Engine
     public function __construct(array $options = array())
     {
         if (isset($options['template_class_prefix'])) {
+            if ((string) $options['template_class_prefix'] === '') {
+                throw new Mustache_Exception_InvalidArgumentException('Mustache Constructor "template_class_prefix" must not be empty');
+            }
+
             $this->templateClassPrefix = $options['template_class_prefix'];
         }
 

+ 10 - 0
test/Mustache/Test/EngineTest.php

@@ -158,6 +158,16 @@ class Mustache_Test_EngineTest extends Mustache_Test_FunctionalTestCase
         $this->assertNotSame($mustache->getCache(), $mustache->getProtectedLambdaCache());
     }
 
+    /**
+     * @expectedException Mustache_Exception_InvalidArgumentException
+     */
+    public function testEmptyTemplatePrefixThrowsException()
+    {
+        new Mustache_Engine(array(
+            'template_class_prefix' => '',
+        ));
+    }
+
     /**
      * @expectedException Mustache_Exception_InvalidArgumentException
      * @dataProvider getBadEscapers