diff --git a/composer.json b/composer.json index 40b4f24..2abc628 100644 --- a/composer.json +++ b/composer.json @@ -32,4 +32,4 @@ "fabpot/php-cs-fixer": "1.7.*", "phpunit/PHPUnit": "~4.0" } -} \ No newline at end of file +} diff --git a/src/Escaper.php b/src/Escaper.php index b732c5e..258dbdf 100644 --- a/src/Escaper.php +++ b/src/Escaper.php @@ -41,13 +41,11 @@ class Escaper /** * Holds the value of the special flags passed as second parameter to - * htmlspecialchars(). We modify these for PHP 5.4 to take advantage - * of the new ENT_SUBSTITUTE flag for correctly dealing with invalid - * UTF-8 sequences. + * htmlspecialchars(). * - * @var string + * @var int */ - protected $htmlSpecialCharsFlags = ENT_QUOTES; + protected $htmlSpecialCharsFlags; /** * Static Matcher which escapes characters for HTML Attribute contexts @@ -89,8 +87,7 @@ class Escaper /** * Constructor: Single parameter allows setting of global encoding for use by - * the current object. If PHP 5.4 is detected, additional ENT_SUBSTITUTE flag - * is set for htmlspecialchars() calls. + * the current object. * * @param string $encoding * @throws Exception\InvalidArgumentException @@ -116,9 +113,8 @@ public function __construct($encoding = null) $this->encoding = $encoding; } - if (defined('ENT_SUBSTITUTE')) { - $this->htmlSpecialCharsFlags|= ENT_SUBSTITUTE; - } + // We take advantage of ENT_SUBSTITUTE flag to correctly deal with invalid UTF-8 sequences. + $this->htmlSpecialCharsFlags = ENT_QUOTES | ENT_SUBSTITUTE; // set matcher callbacks $this->htmlAttrMatcher = [$this, 'htmlAttrMatcher'];