Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty variable containing "&" is transformed

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
zipi
Smarty n00b


Joined: 03 Aug 2017
Posts: 3

PostPosted: Thu Aug 03, 2017 10:07 am    Post subject: Smarty variable containing "&" is transformed Reply with quote

Hello,
Here is my problem :
1. I send to smarty this variable :$url=>http://www.test.com/index.php?var1=toto&var2=tata
2. My tpl code is as it :
Code:

<script type="text/javascript">
                    {$url}
</script>

3. My proble is that the "&" character is transformed by smarty inside the <script> balise. Indeed the & character becomes "&amp;" !

What am I doing wrong ?

Thnaks a lot !
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Aug 03, 2017 11:22 am    Post subject: Reply with quote

First, Smarty knows nothing about <script> in first place.
Second, most likely, you're using blind default escaping.
Back to top
View user's profile Send private message
zipi
Smarty n00b


Joined: 03 Aug 2017
Posts: 3

PostPosted: Thu Aug 03, 2017 2:24 pm    Post subject: Reply with quote

Hello AnrDaemon ! Thks for your answer ! Please could you explicit "you're using blind default escaping" ?
Thanks a lot.
Vins
Back to top
View user's profile Send private message
zipi
Smarty n00b


Joined: 03 Aug 2017
Posts: 3

PostPosted: Thu Aug 03, 2017 2:53 pm    Post subject: Reply with quote

I found the solution !
just put
Code:
<script type="text/javascript">
                    {$url nofilter}
</script>


Thks !
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Aug 03, 2017 3:44 pm    Post subject: Reply with quote

zipi wrote:
Please could you explicit "you're using blind default escaping" ?

https://www.smarty.net/docs/en/variable.default.modifiers.tpl

In general, when you are producing mixed content, (like in your example, HTML+JS) this is a bad idea.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP