[BUGFIX] Strip trailing slash from parsed doc comment 58/48758/2
authorHelmut Hummel <info@helhum.io>
Tue, 28 Jun 2016 07:38:32 +0000 (09:38 +0200)
committerJigal van Hemert <jigal.van.hemert@typo3.org>
Thu, 30 Jun 2016 19:52:50 +0000 (21:52 +0200)
If methods do not end with tag values (arguments or return statement)
the doc comment parser returned a slash as last line,
which is now stripped off.

Resolves: #76815
Releases: master, 7.6
Change-Id: I15d52104c190fbbf1e4ee5146595810f961ca3c7
Reviewed-on: https://review.typo3.org/48758
Reviewed-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
Tested-by: Jigal van Hemert <jigal.van.hemert@typo3.org>
typo3/sysext/extbase/Classes/Reflection/DocCommentParser.php
typo3/sysext/extbase/Tests/Unit/Reflection/DocCommentParserTest.php [new file with mode: 0644]

index b5ae6da..74ac580 100644 (file)
@@ -46,7 +46,7 @@ class DocCommentParser
             if ($line !== '' && strpos($line, '@') !== false) {
                 $this->parseTag(substr($line, strpos($line, '@')));
             } elseif (empty($this->tags)) {
-                $this->description .= preg_replace('/\\s*\\/?[\\\\*]*(.*)$/', '$1', $line) . LF;
+                $this->description .= preg_replace('#\\s*/?[*/]*(.*)$#', '$1', $line) . LF;
             }
         }
         $this->description = trim($this->description);
diff --git a/typo3/sysext/extbase/Tests/Unit/Reflection/DocCommentParserTest.php b/typo3/sysext/extbase/Tests/Unit/Reflection/DocCommentParserTest.php
new file mode 100644 (file)
index 0000000..b856c24
--- /dev/null
@@ -0,0 +1,40 @@
+<?php
+namespace TYPO3\CMS\Extbase\Tests\Unit\Reflection;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+use TYPO3\CMS\Extbase\Reflection\DocCommentParser;
+
+/**
+ * Test case
+ */
+class DocCommentParserTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
+{
+    /**
+     * @test
+     */
+    public function stripsSlashFromMethodComment()
+    {
+        $commentParser = new DocCommentParser();
+        $comment = '/**
+ * Here is some text, but neither an argument nor a return type.
+ */
+';
+        $commentParser->parseDocComment($comment);
+        $this->assertSame(
+            'Here is some text, but neither an argument nor a return type.',
+            $commentParser->getDescription()
+        );
+    }
+}