From d4b06736f256cdd69d3a386535d3f52579d92b76 Mon Sep 17 00:00:00 2001 From: Gnieark Date: Wed, 21 Mar 2018 19:03:56 +0100 Subject: [PATCH] permit alph-numeric and fix unit test --- class.TplBlock.php | 7 +++++-- temp.txt | 1 - test/TplBlockTest.php | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) delete mode 100644 temp.txt diff --git a/class.TplBlock.php b/class.TplBlock.php index ac9a72e..55d46d3 100644 --- a/class.TplBlock.php +++ b/class.TplBlock.php @@ -31,9 +31,13 @@ class TplBlock { public function __construct($name = NULL){ $this->name = $name; + if(!is_null($name) && !ctype_alnum($name)){ + throw new InvalidTemplateException("Only alpha-numerics chars are allowed on the block name"); + return false; + } $this->unusedRegex = '/' . self::blockStartStart - . ' *([a-z][a-z.]*) *' + . ' *([a-z][a-z0-9.]*) *' . self::blockStartEnd . '(.*?)' . self::blockEndStart @@ -66,7 +70,6 @@ class TplBlock { } private function subBlockRegex($prefix, $blocName,$trim = true) { - echo "t".$trim; return '/' . self::blockStartStart . preg_quote($prefix . $blocName) diff --git a/temp.txt b/temp.txt deleted file mode 100644 index 0f130bc..0000000 --- a/temp.txt +++ /dev/null @@ -1 +0,0 @@ -Hello {{name}} \ No newline at end of file diff --git a/test/TplBlockTest.php b/test/TplBlockTest.php index 948128f..63b6ec2 100644 --- a/test/TplBlockTest.php +++ b/test/TplBlockTest.php @@ -34,6 +34,7 @@ class TplBlockTest extends TestCase{ ) ); $this->assertEquals("Hello Gnieark", $tpl->apply_tpl_file("temp.txt")); + unlink("temp.txt"); } //test blocs @@ -55,4 +56,21 @@ class TplBlockTest extends TestCase{ $this->assertFalse(strpos("WONT",$str)); } + //test if error on blocks names WTF + /** + * @expectedException InvalidTemplateException + */ + public function testIfErrorOnForbiddenName(){ + $tpl = new TplBlock("kjsd54 65"); + } + + //test if error on blocks names WTF + /** + * @expectedException InvalidTemplateException + */ + public function testIfErrorOnForbiddenNameAgain(){ + $tpl = new TplBlock("kjsd54.5"); + } + + } \ No newline at end of file