diff --git a/src/Tokenizers/Comment.php b/src/Tokenizers/Comment.php index 335e296cb9..523ce9e41a 100644 --- a/src/Tokenizers/Comment.php +++ b/src/Tokenizers/Comment.php @@ -41,9 +41,16 @@ public function tokenizeString($string, $eolChar, $stackPtr) extra star when they are used for function and class comments. */ - $char = ($numChars - strlen(ltrim($string, '/*'))); - $openTag = substr($string, 0, $char); - $string = ltrim($string, '/*'); + $char = ($numChars - strlen(ltrim($string, '/*'))); + $lastChars = substr($string, -2); + if ($char === $numChars && $lastChars === '*/') { + // Edge case: docblock without whitespace or contents. + $openTag = substr($string, 0, -2); + $string = $lastChars; + } else { + $openTag = substr($string, 0, $char); + $string = ltrim($string, '/*'); + } $tokens[$stackPtr] = [ 'content' => $openTag, diff --git a/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.inc b/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.inc index 923e0fc1b2..88b05ea43c 100644 --- a/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.inc +++ b/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.inc @@ -3,6 +3,9 @@ /* testEmptyBlockCommentNoWhiteSpace */ /**/ +/* testEmptyDocblockNoWhiteSpace */ +/***/ + /* testEmptyDocblockWithWhiteSpace */ /** */ diff --git a/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.php b/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.php index 14c59c607a..e90b573d23 100644 --- a/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.php +++ b/tests/Core/Tokenizer/Comment/SingleLineDocBlockTest.php @@ -28,6 +28,11 @@ final class SingleLineDocBlockTest extends CommentTestCase public static function dataDocblockOpenerCloser() { return [ + 'Single line docblock: empty, no whitespace' => [ + 'marker' => '/* testEmptyDocblockNoWhiteSpace */', + 'closerOffset' => 1, + 'expectedTags' => [], + ], 'Single line docblock: only whitespace' => [ 'marker' => '/* testEmptyDocblockWithWhiteSpace */', 'closerOffset' => 2, @@ -79,12 +84,31 @@ public function testEmptyBlockCommentNoWhiteSpace() /** - * Verify tokenization of an empty, single line DocBlock. + * Verify tokenization of an empty, single line DocBlock without whitespace between the opener and closer. * * @phpcs:disable Squiz.Arrays.ArrayDeclaration.SpaceBeforeDoubleArrow -- Readability is better with alignment. * * @return void */ + public function testEmptyDocblockNoWhiteSpace() + { + $expectedSequence = [ + [T_DOC_COMMENT_OPEN_TAG => '/**'], + [T_DOC_COMMENT_CLOSE_TAG => '*/'], + ]; + + $target = $this->getTargetToken('/* '.__FUNCTION__.' */', T_DOC_COMMENT_OPEN_TAG); + + $this->checkTokenSequence($target, $expectedSequence); + + }//end testEmptyDocblockNoWhiteSpace() + + + /** + * Verify tokenization of an empty, single line DocBlock. + * + * @return void + */ public function testEmptyDocblockWithWhiteSpace() { $expectedSequence = [