merged branch lyrixx/twig-code-ext-warning (PR #8721)

This PR was merged into the 2.2 branch.

Discussion
----------

[TwigBridge] Prevent code extension to display warning

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

During functional testing with phpunit and browserkit (and all their friends) when the application returns a `4XX` or a `5XX` response, symfony displays the trace with code context.

During a training, few people experienced a very weird issue with php 5.4, symfony 2.3.2, phpunit 3.7, Windows 7 or 8 and SensioLabsDesktop 0.5.

When they run functional  tests, and the application returns a `404`, in the "console" there was lot of warnings. It was something like that `Warning: Unexpected character in input:  '\' (ASCII=92) state=1 in /XXXXX on line 9` With the `@`, no more warnings.

I can't reproduce this issue on my computer (not windows). If needed, I can try to reproduce this bug on Monday at work.

Commits
-------

e8e76ec [TwigBridge] Prevent code extension to display warning
This commit is contained in:
Fabien Potencier 2013-08-13 09:32:38 +02:00
commit c07aa94664
2 changed files with 6 additions and 2 deletions

View File

@ -137,7 +137,9 @@ class CodeExtension extends \Twig_Extension
public function fileExcerpt($file, $line)
{
if (is_readable($file)) {
$code = highlight_file($file, true);
// highlight_file could throw warnings
// see https://bugs.php.net/bug.php?id=25725
$code = @highlight_file($file, true);
// remove main code/span tags
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
$content = preg_split('#<br />#', $code);

View File

@ -131,7 +131,9 @@ class CodeHelper extends Helper
}
}
$code = highlight_file($file, true);
// highlight_file could throw warnings
// see https://bugs.php.net/bug.php?id=25725
$code = @highlight_file($file, true);
// remove main code/span tags
$code = preg_replace('#^<code.*?>\s*<span.*?>(.*)</span>\s*</code>#s', '\\1', $code);
$content = preg_split('#<br />#', $code);