[FrameworkBundle] fixed unescaped file_link_format parameter in CodeHelper that made the functional tests fail when checking a 4xx page. The generated file link format used in an HTML stack trace didn't contain an escaped ampersand (&) character. The resulting HTML code was not validable against its DTD and so the Crawler made the tests fail when checking a 4xx page.

This commit is contained in:
Hugo Hamon 2011-12-01 10:53:50 +01:00
parent 83894be6c8
commit 5e5050db53
3 changed files with 17 additions and 3 deletions

View File

@ -86,6 +86,7 @@
<tag name="templating.helper" alias="code" />
<argument>%templating.helper.code.file_link_format%</argument>
<argument>%kernel.root_dir%</argument>
<argument>%kernel.charset%</argument>
</service>
<service id="templating.helper.translator" class="%templating.helper.translator.class%">

View File

@ -13,6 +13,10 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
use Symfony\Component\Templating\Helper\Helper;
if (!defined('ENT_SUBSTITUTE')) {
define('ENT_SUBSTITUTE', 8);
}
/**
* CodeHelper.
*
@ -22,17 +26,20 @@ class CodeHelper extends Helper
{
protected $fileLinkFormat;
protected $rootDir;
protected $charset;
/**
* Constructor.
*
* @param string $fileLinkFormat The format for links to source files
* @param string $rootDir The project root directory
* @param string $charset The charset
*/
public function __construct($fileLinkFormat, $rootDir)
public function __construct($fileLinkFormat, $rootDir, $charset)
{
$this->fileLinkFormat = empty($fileLinkFormat) ? ini_get('xdebug.file_link_format') : $fileLinkFormat;
$this->rootDir = str_replace('\\', '/', $rootDir).'/';
$this->charset = $charset;
}
/**
@ -173,7 +180,7 @@ class CodeHelper extends Helper
}
if (false !== $link = $this->getFileLink($file, $line)) {
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', $link, $text);
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset), $text);
}
return $text;

View File

@ -19,7 +19,13 @@ class CodeHelperTest extends \PHPUnit_Framework_TestCase
static public function setUpBeforeClass()
{
self::$helper = new CodeHelper('format', '/root');
self::$helper = new CodeHelper('txmt://open?url=file://%f&line=%l', '/root', 'UTF-8');
}
public function testFormatFile()
{
$expected = sprintf('<a href="txmt://open?url=file://%s&amp;line=25" title="Click to open this file" class="file_link">%s at line 25</a>', __FILE__, __FILE__);
$this->assertEquals($expected, self::$helper->formatFile(__FILE__, 25));
}
/**