don't override internal PHP constants
This commit is contained in:
parent
97bb22c48c
commit
376cc0332d
|
@ -11,10 +11,6 @@
|
|||
|
||||
namespace Symfony\Bridge\Twig\Extension;
|
||||
|
||||
if (!defined('ENT_SUBSTITUTE')) {
|
||||
define('ENT_SUBSTITUTE', 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* Twig extension relate to PHP code and used by the profiler and the default exception templates.
|
||||
*
|
||||
|
@ -176,7 +172,13 @@ class CodeExtension extends \Twig_Extension
|
|||
$text = "$text at line $line";
|
||||
|
||||
if (false !== $link = $this->getFileLink($file, $line)) {
|
||||
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);
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
} else {
|
||||
$flags = ENT_QUOTES;
|
||||
}
|
||||
|
||||
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
|
|
@ -13,10 +13,6 @@ namespace Symfony\Bundle\FrameworkBundle\Templating\Helper;
|
|||
|
||||
use Symfony\Component\Templating\Helper\Helper;
|
||||
|
||||
if (!defined('ENT_SUBSTITUTE')) {
|
||||
define('ENT_SUBSTITUTE', 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* CodeHelper.
|
||||
*
|
||||
|
@ -170,7 +166,13 @@ 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>', htmlspecialchars($link, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset), $text);
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
} else {
|
||||
$flags = ENT_QUOTES;
|
||||
}
|
||||
|
||||
return sprintf('<a href="%s" title="Click to open this file" class="file_link">%s</a>', htmlspecialchars($link, $flags, $this->charset), $text);
|
||||
}
|
||||
|
||||
return $text;
|
||||
|
|
|
@ -11,8 +11,10 @@
|
|||
|
||||
namespace Symfony\Component\ClassLoader;
|
||||
|
||||
if (!defined('T_TRAIT')) {
|
||||
define('T_TRAIT', 0);
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
define('SYMFONY_TRAIT', T_TRAIT);
|
||||
} else {
|
||||
define('SYMFONY_TRAIT', 0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -113,7 +115,7 @@ class ClassMapGenerator
|
|||
break;
|
||||
case T_CLASS:
|
||||
case T_INTERFACE:
|
||||
case T_TRAIT:
|
||||
case SYMFONY_TRAIT:
|
||||
// Find the classname
|
||||
while (($t = $tokens[++$i]) && is_array($t)) {
|
||||
if (T_STRING === $t[0]) {
|
||||
|
|
|
@ -11,11 +11,6 @@
|
|||
|
||||
namespace Symfony\Component\Console\Input;
|
||||
|
||||
if (!defined('JSON_UNESCAPED_UNICODE')) {
|
||||
define('JSON_UNESCAPED_SLASHES', 64);
|
||||
define('JSON_UNESCAPED_UNICODE', 256);
|
||||
}
|
||||
|
||||
use Symfony\Component\Console\Descriptor\TextDescriptor;
|
||||
use Symfony\Component\Console\Descriptor\XmlDescriptor;
|
||||
|
||||
|
|
|
@ -14,10 +14,6 @@ namespace Symfony\Component\Debug;
|
|||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Debug\Exception\FlattenException;
|
||||
|
||||
if (!defined('ENT_SUBSTITUTE')) {
|
||||
define('ENT_SUBSTITUTE', 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* ExceptionHandler converts an exception to a Response object.
|
||||
*
|
||||
|
@ -292,6 +288,11 @@ EOF;
|
|||
*/
|
||||
private function formatArgs(array $args)
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
} else {
|
||||
$flags = ENT_QUOTES;
|
||||
}
|
||||
$result = array();
|
||||
foreach ($args as $key => $item) {
|
||||
if ('object' === $item[0]) {
|
||||
|
@ -299,7 +300,7 @@ EOF;
|
|||
} elseif ('array' === $item[0]) {
|
||||
$formattedValue = sprintf("<em>array</em>(%s)", is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
|
||||
} elseif ('string' === $item[0]) {
|
||||
$formattedValue = sprintf("'%s'", htmlspecialchars($item[1], ENT_QUOTES | ENT_SUBSTITUTE, $this->charset));
|
||||
$formattedValue = sprintf("'%s'", htmlspecialchars($item[1], $flags, $this->charset));
|
||||
} elseif ('null' === $item[0]) {
|
||||
$formattedValue = '<em>null</em>';
|
||||
} elseif ('boolean' === $item[0]) {
|
||||
|
@ -307,7 +308,7 @@ EOF;
|
|||
} elseif ('resource' === $item[0]) {
|
||||
$formattedValue = '<em>resource</em>';
|
||||
} else {
|
||||
$formattedValue = str_replace("\n", '', var_export(htmlspecialchars((string) $item[1], ENT_QUOTES | ENT_SUBSTITUTE, $this->charset), true));
|
||||
$formattedValue = str_replace("\n", '', var_export(htmlspecialchars((string) $item[1], $flags, $this->charset), true));
|
||||
}
|
||||
|
||||
$result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $key, $formattedValue);
|
||||
|
|
|
@ -11,10 +11,6 @@
|
|||
|
||||
namespace Symfony\Component\HttpKernel\Fragment;
|
||||
|
||||
if (!defined('ENT_SUBSTITUTE')) {
|
||||
define('ENT_SUBSTITUTE', 8);
|
||||
}
|
||||
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
|
@ -111,11 +107,16 @@ class HIncludeFragmentRenderer extends RoutableFragmentRenderer
|
|||
}
|
||||
$renderedAttributes = '';
|
||||
if (count($attributes) > 0) {
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
} else {
|
||||
$flags = ENT_QUOTES;
|
||||
}
|
||||
foreach ($attributes as $attribute => $value) {
|
||||
$renderedAttributes .= sprintf(
|
||||
' %s="%s"',
|
||||
htmlspecialchars($attribute, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false),
|
||||
htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, $this->charset, false)
|
||||
htmlspecialchars($attribute, $flags, $this->charset, false),
|
||||
htmlspecialchars($value, $flags, $this->charset, false)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,10 +17,6 @@ use Symfony\Component\Templating\Storage\StringStorage;
|
|||
use Symfony\Component\Templating\Helper\HelperInterface;
|
||||
use Symfony\Component\Templating\Loader\LoaderInterface;
|
||||
|
||||
if (!defined('ENT_SUBSTITUTE')) {
|
||||
define('ENT_SUBSTITUTE', 8);
|
||||
}
|
||||
|
||||
/**
|
||||
* PhpEngine is an engine able to render PHP templates.
|
||||
*
|
||||
|
@ -466,6 +462,11 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
|||
protected function initializeEscapers()
|
||||
{
|
||||
$that = $this;
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$flags = ENT_QUOTES | ENT_SUBSTITUTE;
|
||||
} else {
|
||||
$flags = ENT_QUOTES;
|
||||
}
|
||||
|
||||
$this->escapers = array(
|
||||
'html' =>
|
||||
|
@ -476,10 +477,10 @@ class PhpEngine implements EngineInterface, \ArrayAccess
|
|||
*
|
||||
* @return string the escaped value
|
||||
*/
|
||||
function ($value) use ($that) {
|
||||
function ($value) use ($that, $flags) {
|
||||
// Numbers and Boolean values get turned into strings which can cause problems
|
||||
// with type comparisons (e.g. === or is_int() etc).
|
||||
return is_string($value) ? htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, $that->getCharset(), false) : $value;
|
||||
return is_string($value) ? htmlspecialchars($value, $flags, $that->getCharset(), false) : $value;
|
||||
},
|
||||
|
||||
'js' =>
|
||||
|
|
|
@ -11,11 +11,6 @@
|
|||
|
||||
namespace Symfony\Component\Yaml\Exception;
|
||||
|
||||
if (!defined('JSON_UNESCAPED_UNICODE')) {
|
||||
define('JSON_UNESCAPED_SLASHES', 64);
|
||||
define('JSON_UNESCAPED_UNICODE', 256);
|
||||
}
|
||||
|
||||
/**
|
||||
* Exception class thrown when an error occurs during parsing.
|
||||
*
|
||||
|
@ -130,7 +125,12 @@ class ParseException extends RuntimeException
|
|||
}
|
||||
|
||||
if (null !== $this->parsedFile) {
|
||||
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$jsonOptions = JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE;
|
||||
} else {
|
||||
$jsonOptions = 0;
|
||||
}
|
||||
$this->message .= sprintf(' in %s', json_encode($this->parsedFile, $jsonOptions));
|
||||
}
|
||||
|
||||
if ($this->parsedLine >= 0) {
|
||||
|
|
|
@ -27,4 +27,16 @@ class ParseExceptionTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$this->assertEquals($message, $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testGetMessageWithUnicodeInFilename()
|
||||
{
|
||||
$exception = new ParseException('Error message', 42, 'foo: bar', 'äöü.yml');
|
||||
if (version_compare(PHP_VERSION, '5.4.0', '>=')) {
|
||||
$message = 'Error message in "äöü.yml" at line 42 (near "foo: bar")';
|
||||
} else {
|
||||
$message = 'Error message in "\u00e4\u00f6\u00fc.yml" at line 42 (near "foo: bar")';
|
||||
}
|
||||
|
||||
$this->assertEquals($message, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
|
Reference in New Issue