From 7ec15ec28532df021266befde408cf8df47b7dda Mon Sep 17 00:00:00 2001
From: Angie Byron <webchick@24967.no-reply.drupal.org>
Date: Sat, 20 Nov 2010 08:27:52 +0000
Subject: [PATCH] #460448 follow-up by chx: Replace advanced regex incompatible
 with PCRE < 7.2 with function-based approach.

---
 includes/common.inc | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)

diff --git a/includes/common.inc b/includes/common.inc
index c8848f5cdc2f..861bdf938c37 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -738,7 +738,7 @@ function drupal_access_denied() {
  *     call may take. The default is 30 seconds. If a timeout occurs, the error
  *     code is set to the HTTP_REQUEST_TIMEOUT constant.
  *   - context: A context resource created with stream_context_create().
- * 
+ *
  * @return object
  *   An object that can have one or more of the following components:
  *   - request: A string containing the request body that was sent.
@@ -3482,12 +3482,9 @@ function drupal_load_stylesheet_content($contents, $optimize = FALSE) {
     );
     // Remove certain whitespace.
     // There are different conditions for removing leading and trailing
-    // whitespace. To be able to use a single backreference in the replacement
-    // string, the outer pattern uses the ?| modifier, which makes all contained
-    // subpatterns appear in \1.
+    // whitespace.
     // @see http://php.net/manual/en/regexp.reference.subpatterns.php
-    $contents = preg_replace('<
-      (?|
+    $contents = preg_replace_callback('<
       # Strip leading and trailing whitespace.
         \s*([@{};,])\s*
       # Strip only leading whitespace from:
@@ -3497,9 +3494,8 @@ function drupal_load_stylesheet_content($contents, $optimize = FALSE) {
       # - Opening parenthesis: Retain "@media (bar) and foo".
       # - Colon: Retain :pseudo-selectors.
       | ([\(:])\s+
-      )
     >xS',
-      '\1',
+      '_drupal_load_stylesheet_content',
       $contents
     );
     // End the file with a new line.
@@ -3513,6 +3509,16 @@ function drupal_load_stylesheet_content($contents, $optimize = FALSE) {
   return $contents;
 }
 
+/**
+ * Helper for drupal_load_stylesheet_content().
+ */
+function _drupal_load_stylesheet_content($matches) {
+  // Discard the full match.
+  unset($matches[0]);
+  // Use the non-empty match.
+  return current(array_filter($matches));
+}
+
 /**
  * Loads stylesheets recursively and returns contents with corrected paths.
  *
-- 
GitLab