Readded escaping to CRM_Utils_Sort and fixed str_replace in CRM_Contact_BAO_Query...
authorMattias Michaux <mattias.michaux@gmail.com>
Tue, 24 May 2016 05:29:06 +0000 (07:29 +0200)
committerMattias Michaux <mattias.michaux@gmail.com>
Tue, 24 May 2016 05:29:06 +0000 (07:29 +0200)
CRM/Contact/BAO/Query.php
CRM/Utils/Sort.php

index d0c25c75175bd5e6687573ed24154c0b0cc1bf94..235b3713ed8839985a716a4a731c8555777014f5 100644 (file)
@@ -4573,8 +4573,8 @@ civicrm_relationship.is_permission_a_b = 0
           if (!empty($orderBy)) {
             // this is special case while searching for
             // change log CRM-1718
-            if (preg_match('/sort_name/i', $orderBy)) {
-              $orderBy = str_replace('sort_name', 'contact_a.sort_name', $orderBy);
+            if (preg_match('/`sort_name`/i', $orderBy)) {
+              $orderBy = str_replace('`sort_name`', '`contact_a`.`sort_name`', $orderBy);
             }
 
             $orderBy = CRM_Utils_Type::escape($orderBy, 'String');
index fec2d400e32d85250d0184a6f6cdb72f984bdc4b..55e2b97704f8d4bc984194889513567aa57d5fcf 100644 (file)
@@ -152,11 +152,11 @@ class CRM_Utils_Sort {
       $this->_vars[$this->_currentSortID]['direction'] == self::DONTCARE
     ) {
       $this->_vars[$this->_currentSortID]['name'] = str_replace(' ', '_', $this->_vars[$this->_currentSortID]['name']);
-      return $this->_vars[$this->_currentSortID]['name'] . ' asc';
+      return CRM_Utils_Type::escape($this->_vars[$this->_currentSortID]['name'], 'MysqlColumnNameOrAlias') . ' asc';
     }
     else {
       $this->_vars[$this->_currentSortID]['name'] = str_replace(' ', '_', $this->_vars[$this->_currentSortID]['name']);
-      return $this->_vars[$this->_currentSortID]['name'] . ' desc';
+      return CRM_Utils_Type::escape($this->_vars[$this->_currentSortID]['name'], 'MysqlColumnNameOrAlias') . ' desc';
     }
   }