Skip to content

Commit

Permalink
Merge pull request #50 from Ocramius/hotfix/#44-match-escaped-quotes
Browse files Browse the repository at this point in the history
Hotfix: match escaped quotes (revert #44)
  • Loading branch information
Ocramius committed Dec 20, 2014
2 parents 433906a + ceaf9ad commit eeda578
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/Doctrine/Common/Annotations/DocLexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function getCatchablePatterns()
return array(
'[a-z_\\\][a-z0-9_\:\\\]*[a-z_][a-z0-9_]*',
'(?:[+-]?[0-9]+(?:[\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
'"(?:[^"])*"',
'"(?:""|[^"])*+"',
);
}

Expand Down
51 changes: 50 additions & 1 deletion tests/Doctrine/Tests/Common/Annotations/DocLexerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,57 @@ public function testWithinDoubleQuotesVeryVeryLongStringWillNotOverflowPregSplit
{
$lexer = new DocLexer();

$lexer->setInput('"' . str_repeat('.', 10240) . '"');
$lexer->setInput('"' . str_repeat('.', 20240) . '"');

$this->assertInternalType('array', $lexer->glimpse());
}

/**
* @group 44
*/
public function testRecognizesDoubleQuotesEscapeSequence()
{
$lexer = new DocLexer();
$docblock = '@Foo("""' . "\n" . '""")';

$tokens = array (
array(
'value' => '@',
'position' => 0,
'type' => DocLexer::T_AT,
),
array(
'value' => 'Foo',
'position' => 1,
'type' => DocLexer::T_IDENTIFIER,
),
array(
'value' => '(',
'position' => 4,
'type' => DocLexer::T_OPEN_PARENTHESIS,
),
array(
'value' => "\"\n\"",
'position' => 5,
'type' => DocLexer::T_STRING,
),
array(
'value' => ')',
'position' => 12,
'type' => DocLexer::T_CLOSE_PARENTHESIS,
),
);

$lexer->setInput($docblock);

foreach ($tokens as $expected) {
$lexer->moveNext();
$lookahead = $lexer->lookahead;
$this->assertEquals($expected['value'], $lookahead['value']);
$this->assertEquals($expected['type'], $lookahead['type']);
$this->assertEquals($expected['position'], $lookahead['position']);
}

$this->assertFalse($lexer->moveNext());
}
}
13 changes: 13 additions & 0 deletions tests/Doctrine/Tests/Common/Annotations/DocParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1282,6 +1282,19 @@ public function testKeyHasNumber()
$this->assertEquals(1, count($annots));
$this->assertEquals(array('foo' => 'test', 'bar2' => 'test'), $annots[0]->settings);
}

/**
* @group 44
*/
public function testSupportsEscapedQuotedValues()
{
$result = $this->createTestParser()->parse('@Doctrine\Tests\Common\Annotations\Name(foo="""bar""")');

$this->assertCount(1, $result);

$this->assertTrue($result[0] instanceof Name);
$this->assertEquals('"bar"', $result[0]->foo);
}
}

/** @Annotation */
Expand Down

0 comments on commit eeda578

Please sign in to comment.