silexphp / Silex

[DEPRECATED -- Use Symfony instead] The PHP micro-framework based on the Symfony Components
https://silex.symfony.com
MIT License
3.58k stars 717 forks source link

Twig_Error_Syntax: Unexpected character "\" in "login.twig" at line 6 #809

Closed viniciuswebdev closed 11 years ago

viniciuswebdev commented 11 years ago

Im getting this error on twig, is my php version old for Silex?

php -v

PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug  6 2012 20:08:59)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH

Thanks!

Full error

in /var/www/signature/vendor/twig/twig/lib/Twig/Lexer.php line 287
at Twig_Lexer->lexExpression() in /var/www/signature/vendor/twig/twig/lib/Twig/Lexer.php line 219
at Twig_Lexer->lexVar() in /var/www/signature/vendor/twig/twig/lib/Twig/Lexer.php line 118
at Twig_Lexer->tokenize('<html> <head> <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"> <title>Gerador de assinaturas</title> {% block stylesheets %} <link href=\"{{ \'public/bootstrap/css/bootstrap.min.css\' }}\" type=\"text/css\" rel=\"stylesheet\" /> <link href=\"{{ \'public/css/style.css\' }}\" type=\"text/css\" rel=\"stylesheet\" /> {% endblock %} </head> <body> <div class=\"container\"> <div class=\"col-md-3\"></div> <div class=\"col-md-6\"> <div class=\"signature-container\"> <h4>Acesso Restrito</h4> <br> <form action=\"/\" method=\"POST\" role=\"form\"> {% if invalid %} <div class=\"alert alert-danger\">Credenciais inválidas</div> {% endif %} <div class=\"form-group\"> <label>Login</label> <input required=\"required\" name=\"login\" class=\"form-control\"> </div> <div class=\"form-group\"> <label>Senha</label> <input required=\"required\" type=\"password\" name=\"password\" class=\"form-control\" > </div>   <button type=\"submit\" class=\"btn btn-success\">Login</button> </form> <div> </div> <div class=\"col-md-3\"></div> </div> </body> ', 'login.twig') in /var/www/signature/vendor/twig/twig/lib/Twig/Environment.php line 451
at Twig_Environment->tokenize('<html> <head> <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"> <title>Gerador de assinaturas</title> {% block stylesheets %} <link href=\"{{ \'public/bootstrap/css/bootstrap.min.css\' }}\" type=\"text/css\" rel=\"stylesheet\" /> <link href=\"{{ \'public/css/style.css\' }}\" type=\"text/css\" rel=\"stylesheet\" /> {% endblock %} </head> <body> <div class=\"container\"> <div class=\"col-md-3\"></div> <div class=\"col-md-6\"> <div class=\"signature-container\"> <h4>Acesso Restrito</h4> <br> <form action=\"/\" method=\"POST\" role=\"form\"> {% if invalid %} <div class=\"alert alert-danger\">Credenciais inválidas</div> {% endif %} <div class=\"form-group\"> <label>Login</label> <input required=\"required\" name=\"login\" class=\"form-control\"> </div> <div class=\"form-group\"> <label>Senha</label> <input required=\"required\" type=\"password\" name=\"password\" class=\"form-control\" > </div>     <button type=\"submit\" class=\"btn btn-success\">Login</button> </form> <div> </div> <div class=\"col-md-3\"></div> </div> </body> ', 'login.twig') in /var/www/signature/vendor/twig/twig/lib/Twig/Environment.php line 537
at Twig_Environment->compileSource('<html> <head> <meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"> <title>Gerador de assinaturas</title> {% block stylesheets %} <link href=\"{{ \'public/bootstrap/css/bootstrap.min.css\' }}\" type=\"text/css\" rel=\"stylesheet\" /> <link href=\"{{ \'public/css/style.css\' }}\" type=\"text/css\" rel=\"stylesheet\" /> {% endblock %} </head> <body> <div class=\"container\"> <div class=\"col-md-3\"></div> <div class=\"col-md-6\"> <div class=\"signature-container\"> <h4>Acesso Restrito</h4> <br> <form action=\"/\" method=\"POST\" role=\"form\"> {% if invalid %} <div class=\"alert alert-danger\">Credenciais inválidas</div> {% endif %} <div class=\"form-group\"> <label>Login</label> <input required=\"required\" name=\"login\" class=\"form-control\"> </div> <div class=\"form-group\"> <label>Senha</label> <input required=\"required\" type=\"password\" name=\"password\" class=\"form-control\" > </div>    <button type=\"submit\" class=\"btn btn-success\">Login</button> </form> <div> </div> <div class=\"col-md-3\"></div> </div> </body> ', 'login.twig') in /var/www/signature/vendor/twig/twig/lib/Twig/Environment.php line 328
at Twig_Environment->loadTemplate('login.twig') in /var/www/signature/vendor/twig/twig/lib/Twig/Environment.php line 296
at Twig_Environment->render('login.twig') in /var/www/signature/web/index.php line 28
at {closure}()
at call_user_func_array(object(Closure), array()) in /var/www/signature/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 117
at HttpKernel->handleRaw(object(Request), '1') in /var/www/signature/vendor/symfony/http-kernel/Symfony/Component/HttpKernel/HttpKernel.php line 61
at HttpKernel->handle(object(Request), '1', true) in /var/www/signature/vendor/silex/silex/src/Silex/Application.php line 511
at Application->handle(object(Request)) in /var/www/signature/vendor/silex/silex/src/Silex/Application.php line 488
at Application->run() in /var/www/signature/web/index.php line 93
stof commented 11 years ago

login.twig is not provided by Silex. Without the source of its line 6, there is no way to help you

viniciuswebdev commented 11 years ago

Thanks @stof

the first lines of login.twig, seems right:

<html>
<head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Title</title>
        {% block stylesheets %}
                <link href="{{ 'public/bootstrap/css/bootstrap.min.css' }}" type="text/css" rel="stylesheet" />
                <link href="{{ 'public/css/style.css' }}" type="text/css" rel="stylesheet" />
        {% endblock %}
</head>
<body>
stof commented 11 years ago

I don't see any \ here

viniciuswebdev commented 11 years ago

The only thing I found in the Internet http://stackoverflow.com/questions/13125007/unexpected-character-in-input-ascii-92-state-1-in-a-silex-application i don't know if may be related, thanks for help

reenl commented 11 years ago

Misconfiguration in your php.ini? http://www.php.net/manual/en/function.set-magic-quotes-runtime.php

viniciuswebdev commented 11 years ago

Thanks @reenl i tried turn on/off but still have this problem, is working fine locally but in production server I get this error.

staabm commented 11 years ago

does your app work on a newer php version?

indeed it looks like an escaping issue, like @reenl already supposed. Where do all those escape chars come from in the stacktrace....?

Maybe your file contains bad newlines or a BOM?

viniciuswebdev commented 11 years ago

@staabm yes, it is working right on a 5.4 version, but I don`t know if the problem is with version or configuration differences.

This is the full template file:

<html>
<head>
        <meta http-equiv="content-type" content="text/html; charset=utf-8">
        <title>Gerador de assinaturas</title>
        {% block stylesheets %}
                <link href="{{ 'public/bootstrap/css/bootstrap.min.css' }}" type="text/css" rel="stylesheet" />
                <link href="{{ 'public/css/style.css' }}" type="text/css" rel="stylesheet" />
        {% endblock %}
</head>
<body>
        <div class="container">
                <div class="col-md-3"></div>
                <div class="col-md-6">
                        <div class="signature-container">
                                <h4>Acesso Restrito</h4>
                                <br>
                                <form action="/" method="POST" role="form">
                                        {% if invalid %}
                                                <div class="alert alert-danger">Credenciais inválidas</div>
                                        {% endif %}
                                        <div class="form-group">
                                                <label>Login</label>
                                                <input required="required" name="login" class="form-control">
                                        </div>
                                        <div class="form-group">
                                                <label>Senha</label>
                                                <input required="required" type="password" name="password" class="form-control" >
                                        </div>
                                        <button type="submit" class="btn btn-success">Login</button>
                                </form>
                        <div>
                </div>
                <div class="col-md-3"></div>
           </div>
</body>
fabpot commented 11 years ago

Closing as support should be done on the mailing-list.