summaryrefslogtreecommitdiff
path: root/includes/unicode.inc
diff options
context:
space:
mode:
authorDries Buytaert <dries@buytaert.net>2010-07-29 00:38:24 +0000
committerDries Buytaert <dries@buytaert.net>2010-07-29 00:38:24 +0000
commita80919186c5a3f5edc10ee80cef72fdd64ba9911 (patch)
tree8929b4e54aa083152e62c97cd7029d2d94d34234 /includes/unicode.inc
parentc9e5a055fb0a83ea96ae89fd908747dac37b0923 (diff)
downloadbrdo-a80919186c5a3f5edc10ee80cef72fdd64ba9911.tar.gz
brdo-a80919186c5a3f5edc10ee80cef72fdd64ba9911.tar.bz2
- Patch #855988 by pwolanin, Damien Tournoud, David_Rothstein: get rid of preg_replace() with /e in decode_entities().
Diffstat (limited to 'includes/unicode.inc')
-rw-r--r--includes/unicode.inc37
1 files changed, 27 insertions, 10 deletions
diff --git a/includes/unicode.inc b/includes/unicode.inc
index 05ce8f89e..89d3d6f2e 100644
--- a/includes/unicode.inc
+++ b/includes/unicode.inc
@@ -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.