From 8b569e49a193abcc28689dfc68058da9d80d4121 Mon Sep 17 00:00:00 2001 From: Fabien Potencier Date: Fri, 8 Feb 2013 19:58:08 +0100 Subject: [PATCH] added a note about how to use quotes in strings (closes #973) --- doc/templates.rst | 5 +++-- test/Twig/Tests/LexerTest.php | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/doc/templates.rst b/doc/templates.rst index 5e3b678..94eb9f9 100644 --- a/doc/templates.rst +++ b/doc/templates.rst @@ -569,8 +569,9 @@ exist: * ``"Hello World"``: Everything between two double or single quotes is a string. They are useful whenever you need a string in the template (for - example as arguments to function calls, filters or just to extend or - include a template). + example as arguments to function calls, filters or just to extend or include + a template). A string can contain a delimiter if it is preceded by a + backslash (``\``) -- like in ``'It\'s good'``. * ``42`` / ``42.23``: Integers and floating point numbers are created by just writing the number down. If a dot is present the number is a float, diff --git a/test/Twig/Tests/LexerTest.php b/test/Twig/Tests/LexerTest.php index ce87898..cb1cc3c 100644 --- a/test/Twig/Tests/LexerTest.php +++ b/test/Twig/Tests/LexerTest.php @@ -150,7 +150,21 @@ class Twig_Tests_LexerTest extends PHPUnit_Framework_TestCase $this->assertEquals(922337203685477580700, $node->getValue()); } - public function testString() + public function testStringWithEscapedDelimiter() + { + $tests = array( + "{{ 'foo \' bar' }}" => 'foo \' bar', + '{{ "foo \" bar" }}' => "foo \" bar", + ); + $lexer = new Twig_Lexer(new Twig_Environment()); + foreach ($tests as $template => $expected) { + $stream = $lexer->tokenize($template); + $stream->expect(Twig_Token::VAR_START_TYPE); + $stream->expect(Twig_Token::STRING_TYPE, $expected); + } + } + + public function testStringWithInterpolation() { $template = 'foo {{ "bar #{ baz + 1 }" }}'; -- 1.7.2.5