Commit 881eb212 authored by beberlei's avatar beberlei

[2.0] Added test that shows AnnotationParser only parses string literals with...

[2.0] Added test that shows AnnotationParser only parses string literals with double quotes, wheras single quotes throw an Syntax Error. Removed debug output on failure for a proper syntax error exception.
parent 1eec9f21
...@@ -31,6 +31,7 @@ namespace Doctrine\Common\Annotations; ...@@ -31,6 +31,7 @@ namespace Doctrine\Common\Annotations;
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> * @author Guilherme Blanco <guilhermeblanco@hotmail.com>
* @author Jonathan Wage <jonwage@gmail.com> * @author Jonathan Wage <jonwage@gmail.com>
* @author Roman Borschel <roman@code-factory.org> * @author Roman Borschel <roman@code-factory.org>
* @author Benjamin Eberlei <kontakt@beberlei.de>
*/ */
class Parser class Parser
{ {
...@@ -165,7 +166,7 @@ class Parser ...@@ -165,7 +166,7 @@ class Parser
if ($this->_lexer->lookahead === null) { if ($this->_lexer->lookahead === null) {
$message .= 'end of string.'; $message .= 'end of string.';
} else { } else {
$message .= "'{$token['value']}'"; $message .= "'{$token['value']}' at position {$token['position']}.";
} }
throw AnnotationException::syntaxError($message); throw AnnotationException::syntaxError($message);
...@@ -357,8 +358,7 @@ class Parser ...@@ -357,8 +358,7 @@ class Parser
return false; return false;
default: default:
var_dump($this->_lexer->lookahead); $this->syntaxError('PlainValue');
throw new \Exception("Invalid value.");
} }
} }
......
...@@ -90,6 +90,24 @@ DOCBLOCK; ...@@ -90,6 +90,24 @@ DOCBLOCK;
$this->assertEquals(0, count($result)); $this->assertEquals(0, count($result));
} }
public function testAnnotationDontAcceptSingleQuotes()
{
$this->setExpectedException(
'Doctrine\Common\Annotations\AnnotationException',
"[Syntax Error] Expected 'PlainValue', got ''' at position 10."
);
$parser = $this->createTestParser();
$parser->parse("@Name(foo='bar')");
}
public function createTestParser()
{
$parser = new Parser();
$parser->setDefaultAnnotationNamespace('Doctrine\Tests\Common\Annotations\\');
return $parser;
}
} }
class Name extends \Doctrine\Common\Annotations\Annotation { class Name extends \Doctrine\Common\Annotations\Annotation {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment