diff --git a/src/Symfony/Components/Templating/Engine.php b/src/Symfony/Components/Templating/Engine.php
index 75a332d2a7..0baf4485d9 100644
--- a/src/Symfony/Components/Templating/Engine.php
+++ b/src/Symfony/Components/Templating/Engine.php
@@ -182,7 +182,7 @@ class Engine
$this->helpers[$alias] = $helper;
}
- $helper->setEngine($this);
+ $helper->setCharset($this->charset);
}
/**
diff --git a/src/Symfony/Components/Templating/Helper/Helper.php b/src/Symfony/Components/Templating/Helper/Helper.php
index 7b99c7364e..c1d65bb320 100644
--- a/src/Symfony/Components/Templating/Helper/Helper.php
+++ b/src/Symfony/Components/Templating/Helper/Helper.php
@@ -2,8 +2,6 @@
namespace Symfony\Components\Templating\Helper;
-use Symfony\Components\Templating\Engine;
-
/*
* This file is part of the symfony package.
*
@@ -22,25 +20,25 @@ use Symfony\Components\Templating\Engine;
*/
abstract class Helper implements HelperInterface
{
- protected $engine;
+ protected $charset = 'UTF-8';
/**
- * Sets the engine associated with this helper.
+ * Sets the default charset.
*
- * @param Engine $engine A Engine instance
+ * @param string $charset The charset
*/
- public function setEngine(Engine $engine = null)
+ public function setCharset($charset)
{
- $this->engine = $engine;
+ $this->charset = $charset;
}
/**
- * Gets the engine associated with this helper.
+ * Gets the default charset.
*
- * @return Engine A Engine instance
+ * @return string The default charset
*/
- public function getEngine()
+ public function getCharset()
{
- return $this->engine;
+ return $this->charset;
}
}
diff --git a/src/Symfony/Components/Templating/Helper/HelperInterface.php b/src/Symfony/Components/Templating/Helper/HelperInterface.php
index 389abc5193..a2570cad17 100644
--- a/src/Symfony/Components/Templating/Helper/HelperInterface.php
+++ b/src/Symfony/Components/Templating/Helper/HelperInterface.php
@@ -2,8 +2,6 @@
namespace Symfony\Components\Templating\Helper;
-use Symfony\Components\Templating\Engine;
-
/*
* This file is part of the symfony package.
*
@@ -30,16 +28,16 @@ interface HelperInterface
function getName();
/**
- * Sets the engine associated with this helper.
+ * Sets the default charset.
*
- * @param Engine $engine A Engine instance
+ * @param string $charset The charset
*/
- function setEngine(Engine $engine = null);
+ function setCharset($charset);
/**
- * Gets the engine associated with this helper.
+ * Gets the default charset.
*
- * @return Engine A Engine instance
+ * @return string The default charset
*/
- function getEngine();
+ function getCharset();
}
diff --git a/src/Symfony/Components/Templating/Helper/JavascriptsHelper.php b/src/Symfony/Components/Templating/Helper/JavascriptsHelper.php
index fcacd03cfe..8480b8e5ca 100644
--- a/src/Symfony/Components/Templating/Helper/JavascriptsHelper.php
+++ b/src/Symfony/Components/Templating/Helper/JavascriptsHelper.php
@@ -28,6 +28,17 @@ namespace Symfony\Components\Templating\Helper;
class JavascriptsHelper extends Helper
{
protected $javascripts = array();
+ protected $assetHelper;
+
+ /**
+ * Constructor.
+ *
+ * @param AssetsHelper $assetHelper A AssetsHelper instance
+ */
+ public function __construct(AssetsHelper $assetHelper)
+ {
+ $this->assetHelper = $assetHelper;
+ }
/**
* Adds a JavaScript file.
@@ -37,7 +48,7 @@ class JavascriptsHelper extends Helper
*/
public function add($javascript, $attributes = array())
{
- $this->javascripts[$this->engine->get('assets')->getUrl($javascript)] = $attributes;
+ $this->javascripts[$this->assetHelper->getUrl($javascript)] = $attributes;
}
/**
@@ -63,7 +74,7 @@ class JavascriptsHelper extends Helper
$atts = '';
foreach ($attributes as $key => $value)
{
- $atts .= ' '.sprintf('%s="%s"', $key, $this->engine->escape($value));
+ $atts .= ' '.sprintf('%s="%s"', $key, htmlspecialchars($value, ENT_QUOTES, $this->charset));
}
$html .= sprintf('', $path, $atts)."\n";
diff --git a/src/Symfony/Components/Templating/Helper/StylesheetsHelper.php b/src/Symfony/Components/Templating/Helper/StylesheetsHelper.php
index 900d8254c9..94d4cf3c8c 100644
--- a/src/Symfony/Components/Templating/Helper/StylesheetsHelper.php
+++ b/src/Symfony/Components/Templating/Helper/StylesheetsHelper.php
@@ -28,6 +28,17 @@ namespace Symfony\Components\Templating\Helper;
class StylesheetsHelper extends Helper
{
protected $stylesheets = array();
+ protected $assetHelper;
+
+ /**
+ * Constructor.
+ *
+ * @param AssetsHelper $assetHelper A AssetsHelper instance
+ */
+ public function __construct(AssetsHelper $assetHelper)
+ {
+ $this->assetHelper = $assetHelper;
+ }
/**
* Adds a stylesheets file.
@@ -37,7 +48,7 @@ class StylesheetsHelper extends Helper
*/
public function add($stylesheet, $attributes = array())
{
- $this->stylesheets[$this->engine->get('assets')->getUrl($stylesheet)] = $attributes;
+ $this->stylesheets[$this->assetHelper->getUrl($stylesheet)] = $attributes;
}
/**
@@ -63,7 +74,7 @@ class StylesheetsHelper extends Helper
$atts = '';
foreach ($attributes as $key => $value)
{
- $atts .= ' '.sprintf('%s="%s"', $key, $this->engine->escape($value));
+ $atts .= ' '.sprintf('%s="%s"', $key, htmlspecialchars($value, ENT_QUOTES, $this->charset));
}
$html .= sprintf('', $path, $atts)."\n";
diff --git a/src/Symfony/Framework/WebBundle/Templating/Engine.php b/src/Symfony/Framework/WebBundle/Templating/Engine.php
index d6b8fcecac..e4f6126df8 100644
--- a/src/Symfony/Framework/WebBundle/Templating/Engine.php
+++ b/src/Symfony/Framework/WebBundle/Templating/Engine.php
@@ -87,7 +87,7 @@ class Engine extends BaseEngine
if (is_string($this->helpers[$name]))
{
$this->helpers[$name] = $this->container->getService('templating.helper.'.$name);
- $this->helpers[$name]->setEngine($this);
+ $this->helpers[$name]->setCharset($this->charset);
}
return $this->helpers[$name];