Skip to content

Commit d1b379c

Browse files
mrtnzlmldg
authored andcommitted
ComponentReflection::parseAnnotation: fix false positive annotation parsing (#151)
1 parent d47e06c commit d1b379c

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Application/UI/ComponentReflection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static function convertType(& $val, $type, $isClass = FALSE)
195195
*/
196196
public static function parseAnnotation(\Reflector $ref, $name)
197197
{
198-
if (!preg_match_all('#[\\s*]@' . preg_quote($name, '#') . '(?:\(\\s*([^)]*)\\s*\))?#', $ref->getDocComment(), $m)) {
198+
if (!preg_match_all('#[\\s*]@' . preg_quote($name, '#') . '(?:\(\\s*([^)]*)\\s*\)|\\s|$)#', $ref->getDocComment(), $m)) {
199199
return FALSE;
200200
}
201201
static $tokens = ['true' => TRUE, 'false' => FALSE, 'null' => NULL];

tests/UI/ComponentReflection.parseAnnotation.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ require __DIR__ . '/../bootstrap.php';
1515
* @title(value ="Johno's addendum", mode=True,) , out
1616
* @title
1717
* @title()
18+
* @publi - 'c' is missing intentionally
19+
* @privatex
1820
* @components(item 1)
1921
* @persistent(true)
2022
* @persistent(FALSE)
@@ -30,6 +32,8 @@ class TestClass {}
3032
$rc = new ReflectionClass('TestClass');
3133

3234
Assert::same(['value ="Johno\'s addendum"', 'mode=True', TRUE, TRUE], Reflection::parseAnnotation($rc, 'title'));
35+
Assert::same(FALSE, Reflection::parseAnnotation($rc, 'public'));
36+
Assert::same(FALSE, Reflection::parseAnnotation($rc, 'private'));
3337
Assert::same(['item 1'], Reflection::parseAnnotation($rc, 'components'));
3438
Assert::same([TRUE, FALSE, NULL], Reflection::parseAnnotation($rc, 'persistent'));
3539
Assert::same([TRUE], Reflection::parseAnnotation($rc, 'renderable'));

0 commit comments

Comments
 (0)