Skip to content

Commit 31bd54b

Browse files
committed
Fix variable prefix restriction + unit tests
1 parent ade086e commit 31bd54b

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/JsPhpize/Lexer/Scanner.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function scanOperator($matches)
7171
public function scanVariable($matches)
7272
{
7373
$varPrefix = $this->engine->getOption('varPrefix', JsPhpize::VAR_PREFIX);
74-
if (substr($matches[0], 0, 5) === $varPrefix) {
75-
throw new Exception('Variables cannot start with ' . $varPrefix . ', this prefix is reserved for JsPhpize' . $this->exceptionInfos(), 1);
74+
if (strpos($matches[1], $varPrefix) === 0) {
75+
throw new Exception('Variables cannot start with ' . $varPrefix . ', this prefix is reserved for JsPhpize' . $this->exceptionInfos(), 4);
7676
}
7777

7878
return $this->valueToken('variable', $matches);

tests/options.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,18 @@ public function testConstPrefixRestriction()
5252
var a = FOOBAR;
5353
');
5454
}
55+
56+
/**
57+
* @expectedException \JsPhpize\Lexer\Exception
58+
* @expectedExceptionCode 4
59+
*/
60+
public function testVarPrefixRestriction()
61+
{
62+
$jsPhpize = new JsPhpize(array(
63+
'varPrefix' => 'test',
64+
));
65+
$jsPhpize->render('
66+
var a = test_zz;
67+
');
68+
}
5569
}

0 commit comments

Comments
 (0)