diff --git a/library/Zend/Code/Scanner/AnnotationScanner.php b/library/Zend/Code/Scanner/AnnotationScanner.php index dc785f5109a..7fb8e6397c8 100644 --- a/library/Zend/Code/Scanner/AnnotationScanner.php +++ b/library/Zend/Code/Scanner/AnnotationScanner.php @@ -213,7 +213,7 @@ protected function tokenize() } if ($MACRO_HAS_CONTEXT($CONTEXT_CLASS)) { - if (in_array($currentChar, array(' ', '(', "\n"))) { + if (in_array($currentChar, array(' ', '(', "\n", "\r"))) { $context &= ~$CONTEXT_CLASS; $MACRO_TOKEN_ADVANCE(); } else { @@ -225,8 +225,9 @@ protected function tokenize() } } - // Since we don't know what line endings are used in the file, we check for all scenarios. If we find - // a cariage return (\r), we check the next character for a line feed (\n). If so we consume it. + // Since we don't know what line endings are used in the file, we check for all scenarios. If we find a + // cariage return (\r), we check the next character for a line feed (\n). If so we consume it and act as + // if the cariage return was a line feed. $lineEnded = $currentChar === "\n"; if ($currentChar === "\r") { $lineEnded = true; @@ -235,6 +236,8 @@ protected function tokenize() if ($nextChar !== "\n") { $streamIndex--; } + + $currentChar = "\n"; } if ($lineEnded) { diff --git a/tests/ZendTest/Code/Scanner/AnnotationScannerTest.php b/tests/ZendTest/Code/Scanner/AnnotationScannerTest.php index 9ae1d193a2f..32ac3c2f43b 100644 --- a/tests/ZendTest/Code/Scanner/AnnotationScannerTest.php +++ b/tests/ZendTest/Code/Scanner/AnnotationScannerTest.php @@ -16,7 +16,10 @@ class AnnotationScannerTest extends \PHPUnit_Framework_TestCase { - public function testScannerWorks() + /** + * @dataProvider scannerWorksDataProvider + */ + public function testScannerWorks($newLine) { $annotationManager = new AnnotationManager(); $parser = new GenericAnnotationParser(); @@ -26,9 +29,10 @@ public function testScannerWorks() )); $annotationManager->attach($parser); - $docComment = '/**' . "\n" - . ' * @Test\Foo(\'anything I want()' . "\n" . ' * to be\')' . "\n" - . ' * @Test\Bar' . "\n */"; + $docComment = '/**' . $newLine + . ' * @Test\Foo(\'anything I want()' . $newLine + . ' * to be\')' . $newLine + . ' * @Test\Bar' . $newLine . " */"; $nameInfo = new NameInformation(); $nameInfo->addUse('ZendTest\Code\Scanner\TestAsset\Annotation', 'Test'); @@ -38,4 +42,13 @@ public function testScannerWorks() $this->assertEquals("'anything I want()\n to be'", $annotationScanner[0]->getContent()); $this->assertEquals(get_class($bar), get_class($annotationScanner[1])); } + + public function scannerWorksDataProvider() + { + return array( + array("\n"), + array("\r"), + array("\r\n"), + ); + } }