From 6f5182a34a8fda0f852b8d985c7280bec1858ba9 Mon Sep 17 00:00:00 2001 From: sundeep8967 Date: Wed, 30 Sep 2026 23:41:09 +0530 Subject: [PATCH] fix(AppFramework): Safely parse parenthesised annotations without equals In ControllerMethodReflector::reflect(), parenthesised annotations were unconditionally split on '=', assuming every entry followed a key=value format. For annotations without '=' (such as @SuppressWarnings(PHPMD.X)), exploding without '=' returned a 1-element array, triggering PHP warnings: 'Undefined array key 1'. - Only split on '=' when '=' is present in the annotation element. - Avoid shadowing outer foreach loop variable $key with param key. - Add unit test testGetAnnotationParenthesisedWithoutEquals. Fixes #64861 Signed-off-by: sundeep8967 --- .../Utility/ControllerMethodReflector.php | 8 ++++++-- .../Utility/ControllerMethodReflectorTest.php | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/private/AppFramework/Utility/ControllerMethodReflector.php b/lib/private/AppFramework/Utility/ControllerMethodReflector.php index 3c2a7d01f618e..b610b7169e129 100644 --- a/lib/private/AppFramework/Utility/ControllerMethodReflector.php +++ b/lib/private/AppFramework/Utility/ControllerMethodReflector.php @@ -57,8 +57,12 @@ public function reflect($object, string $method) { $cutString = str_replace(' ', '', $cutString); $splitArray = explode(',', $cutString); foreach ($splitArray as $annotationValues) { - [$key, $value] = explode('=', $annotationValues); - $this->annotations[$annotation][$key] = $value; + if (!str_contains($annotationValues, '=')) { + $this->annotations[$annotation][$annotationValues] = ''; + continue; + } + [$paramKey, $paramValue] = explode('=', $annotationValues, 2); + $this->annotations[$annotation][$paramKey] = $paramValue; } continue; } diff --git a/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php b/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php index 618f3feef9c3c..4574fcdd7554f 100644 --- a/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php +++ b/tests/lib/AppFramework/Utility/ControllerMethodReflectorTest.php @@ -145,6 +145,21 @@ public function testGetAnnotationParameterMultiple(): void { $this->assertSame('value3', $reader->getAnnotationParameter('Annotation', 'parameter3')); } + /** + * @SuppressWarnings(PHPMD.CyclomaticComplexity, PHPMD.ExcessiveMethodLength) + */ + public function testGetAnnotationParenthesisedWithoutEquals(): void { + $reader = new ControllerMethodReflector(Server::get(LoggerInterface::class)); + $reader->reflect( + self::class, + __FUNCTION__ + ); + + $this->assertTrue($reader->hasAnnotation('SuppressWarnings')); + $this->assertSame('', $reader->getAnnotationParameter('SuppressWarnings', 'PHPMD.CyclomaticComplexity')); + $this->assertSame('', $reader->getAnnotationParameter('SuppressWarnings', 'PHPMD.ExcessiveMethodLength')); + } + /** * @Annotation * @param test