Skip to content

[BUG]: Phalcon\Annotations\Reader crushes when annotation contains unclosed parentheses #16084

@gapki

Description

@gapki

Describe the bug
Phalcon\Annotations\Reader cannot parse from class containing any annotation including unclosed parentheses in its value.
If this issue is duplicated or fixed in later versions, please excuse me for not investigating further and close this issue. 🙏

To Reproduce

Steps to reproduce the behavior:

working class code

class TestClass
{
    /** @SomeAnnotation(key='value') */
    public string $some_property;
}

non-working class code

class TestClass
{
    /** @SomeAnnotation(key='value(') */
    public string $some_property;
}

test code

use Phalcon\Annotations\Reader;

class SampleTest
{
    public function test(): void
    {
        $reader = new Reader();
        $reader->parse('TestClass');
    }
}

Expected behavior
Smooth parsing done with both working and non-working classes.

Actual behavior
An exception thrown as follows when tested with the non-working class above:

PHP Phalcon\Annotations\Exception:  Scanning error before '/' in /opt/project/app/models/TestClass.php on line 1 in /opt/project/tests/Unit/common/sample/SampleUnitTest.php on line 24
PHP Stack trace:
PHP   1. {main}() /opt/project/vendor/phpunit/phpunit/phpunit:0
PHP   2. PHPUnit\TextUI\Command::main($exit = *uninitialized*) /opt/project/vendor/phpunit/phpunit/phpunit:61
PHP   3. PHPUnit\TextUI\Command->run($argv = *uninitialized*, $exit = *uninitialized*) /opt/project/vendor/phpunit/phpunit/src/TextUI/Command.php:95
PHP   4. PHPUnit\TextUI\TestRunner->run($suite = *uninitialized*, $arguments = *uninitialized*, $warnings = *uninitialized*, $exit = *uninitialized*) /opt/project/vendor/phpunit/phpunit/src/TextUI/Command.php:142
PHP   5. PHPUnit\Framework\TestSuite->run($result = *uninitialized*) /opt/project/vendor/phpunit/phpunit/src/TextUI/TestRunner.php:667
PHP   6. PHPUnit\Framework\TestSuite->run($result = *uninitialized*) /opt/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
PHP   7. Tests\Unit\common\sample\SampleUnitTest->run($result = *uninitialized*) /opt/project/vendor/phpunit/phpunit/src/Framework/TestSuite.php:677
PHP   8. PHPUnit\Framework\TestResult->run($test = *uninitialized*) /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:884
PHP   9. Tests\Unit\common\sample\SampleUnitTest->runBare() /opt/project/vendor/phpunit/phpunit/src/Framework/TestResult.php:722
PHP  10. Tests\Unit\common\sample\SampleUnitTest->runTest() /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:1132
PHP  11. Tests\Unit\common\sample\SampleUnitTest->testVoid() /opt/project/vendor/phpunit/phpunit/src/Framework/TestCase.php:1526
PHP  12. Phalcon\Annotations\Reader->parse(*uninitialized*) /opt/project/tests/Unit/common/sample/SampleUnitTest.php:24

Details

  • Phalcon version: 4.0.6
  • PHP Version: 7.4
  • Operating System: MacOS
  • Installation type: installing via package manager
  • Zephir version (if any): N/A
  • Server: Nginx
  • Other related info (Database, table schema): N/A

Metadata

Metadata

Assignees

Labels

5.0The issues we want to solve in the 5.0 releasebugA bug reportstatus: mediumMedium

Type

No fields configured for Bug.

Projects

Status
Implemented

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions