From 15da99446c11fd9e27d30e240472eb586b0ccee9 Mon Sep 17 00:00:00 2001 From: Franck Allimant Date: Sat, 31 May 2014 16:27:32 +0200 Subject: [PATCH] Added "js" parameter to intl function for a safe usage in JS string, --- .../Core/Template/Smarty/Plugins/Translation.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php b/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php index aa66c114f..22ba0d14f 100644 --- a/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php +++ b/core/lib/Thelia/Core/Template/Smarty/Plugins/Translation.php @@ -47,20 +47,26 @@ class Translation extends AbstractSmartyPlugin */ public function translate($params, &$smarty) { - // All parameters other than 'l' and 'd' are supposed to be variables. Build an array of var => value pairs + // All parameters other than 'l' and 'd' and 'js' are supposed to be variables. Build an array of var => value pairs // and pass it to the translator $vars = array(); foreach ($params as $name => $value) { - if ($name != 'l' && $name != 'd') $vars["%$name"] = $value; + if ($name != 'l' && $name != 'd' && $name != 'js') $vars["%$name"] = $value; } - return $this->translator->trans( + $str = $this->translator->trans( $this->getParam($params, 'l'), $vars, $this->getParam($params, 'd', $this->defaultTranslationDomain) ); -} + + if ($this->getParam($params, 'js', 0)) { + $str = preg_replace("/(['\"])/", "\\\\$1", $str); + } + + return $str; + } /** * Define the various smarty plugins handled by this class