Browse Source

Annotation - fix for Windows line endings

SpacePossum 4 years ago
parent
commit
a26b8353de

+ 1 - 1
src/DocBlock/Annotation.php

@@ -302,7 +302,7 @@ class Annotation
             }
 
             $matchingResult = Preg::match(
-                '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.self::REGEX_TYPES.'(?:[*\h].*)?$}sx',
+                '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.self::REGEX_TYPES.'(?:[*\h].*)?\r?$}sx',
                 $this->lines[0]->getContent(),
                 $matches
             );

+ 8 - 0
tests/DocBlock/AnnotationTest.php

@@ -285,6 +285,14 @@ final class AnnotationTest extends TestCase
                 ' * @method int method()',
                 ['int'],
             ],
+            [
+                " * @return int[]\r",
+                ['int[]'],
+            ],
+            [
+                " * @return int[]\r\n",
+                ['int[]'],
+            ],
             [
                 ' * @method Foo[][] method()',
                 ['Foo[][]'],

+ 8 - 0
tests/Fixer/Phpdoc/PhpdocTypesFixerTest.php

@@ -25,6 +25,14 @@ use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  */
 final class PhpdocTypesFixerTest extends AbstractFixerTestCase
 {
+    public function testWindowsLinebreaks()
+    {
+        $this->doTest(
+            "<?php /**\r\n * @param string|string[] \$bar\r\n *\r\n * @return int[]\r\n */\r\n",
+            "<?php /**\r\n * @param STRING|String[] \$bar\r\n *\r\n * @return inT[]\r\n */\r\n"
+        );
+    }
+
     public function testConversion()
     {
         $expected = <<<'EOF'