[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.
This commit is contained in:
parent
1eec9f211b
commit
881eb212d2
2 changed files with 21 additions and 3 deletions
|
@ -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
|
||||||
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
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
var_dump($this->_lexer->lookahead);
|
$this->syntaxError('PlainValue');
|
||||||
throw new \Exception("Invalid value.");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
Loading…
Add table
Reference in a new issue