Skip to content

Commit ade086e

Browse files
committed
Fix constant prefix restriction + unit tests
1 parent 6a8b3cc commit ade086e

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/JsPhpize/Lexer/Scanner.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public function scanConstant($matches)
2020
{
2121
$constant = trim($matches[0]);
2222
$constPrefix = $this->engine->getOption('constPrefix', JsPhpize::CONST_PREFIX);
23-
if (substr($constant, 0, 5) === $constPrefix) {
23+
if (strpos($constant, $constPrefix) === 0) {
2424
throw new Exception('Constants cannot start with ' . $constPrefix . ', this prefix is reserved for JsPhpize' . $this->exceptionInfos(), 1);
2525
}
2626
$translate = array(

tests/options.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,18 @@ public function testDisallow()
3838
}
3939
$this->assertSame(3, $code);
4040
}
41+
42+
/**
43+
* @expectedException \JsPhpize\Lexer\Exception
44+
* @expectedExceptionCode 1
45+
*/
46+
public function testConstPrefixRestriction()
47+
{
48+
$jsPhpize = new JsPhpize(array(
49+
'constPrefix' => 'FOO',
50+
));
51+
$jsPhpize->render('
52+
var a = FOOBAR;
53+
');
54+
}
4155
}

0 commit comments

Comments
 (0)