Skip to content
Snippets Groups Projects
Commit a8091918 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #855988 by pwolanin, Damien Tournoud, David_Rothstein: get rid of...

- Patch #855988 by pwolanin, Damien Tournoud, David_Rothstein: get rid of preg_replace() with /e in decode_entities().
parent c9e5a055
No related branches found
No related tags found
No related merge requests found
......@@ -430,25 +430,42 @@ function _mime_header_decode($matches) {
* The input $text, with all HTML entities decoded once.
*/
function decode_entities($text, $exclude = array()) {
static $html_entities;
if (!isset($html_entities)) {
include DRUPAL_ROOT . '/includes/unicode.entities.inc';
}
// Flip the exclude list so that we can do quick lookups later.
$exclude = array_flip($exclude);
// Prepare the callback function.
_decode_entities(NULL, $exclude);
// Use a regexp to select all entities in one pass, to avoid decoding
// double-escaped entities twice. The PREG_REPLACE_EVAL modifier 'e' is
// being used to allow for a callback (see
// http://php.net/manual/en/reference.pcre.pattern.modifiers).
return preg_replace('/&(#x?)?([A-Za-z0-9]+);/e', '_decode_entities("$1", "$2", "$0", $html_entities, $exclude)', $text);
// double-escaped entities twice.
return preg_replace_callback('/&(#x?)?([A-Za-z0-9]+);/', '_decode_entities', $text);
}
/**
* Helper function for decode_entities
*
* @param $matches
* An array of matches found by preg_replace_callback(). Elements 0, 1, and 2
* of $matches must be the original entity, its prefix, and its codepoint.
* @param $set_exclude
* An array of entities that should be excluded from decoding. This should
* only be set during a preparatory call before preg_replace_callback().
*
* @return
* The decoded entity for a given match, or the original encoded entity if
* the entity is in the list of excluded entities.
*/
function _decode_entities($prefix, $codepoint, $original, &$html_entities, &$exclude) {
function _decode_entities($matches = NULL, $set_exclude = NULL) {
static $html_entities, $exclude;
if (!isset($html_entities)) {
include DRUPAL_ROOT . '/includes/unicode.entities.inc';
}
if (isset($set_exclude)) {
// This is a preparatory call.
$exclude = $set_exclude;
return;
}
list($original, $prefix, $codepoint) = $matches;
// Named entity
if (!$prefix) {
// A named entity not in the exclude list.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment