diff --git a/Solr_Base_Query.php b/Solr_Base_Query.php
index 95373d6..207cd8e 100644
--- a/Solr_Base_Query.php
+++ b/Solr_Base_Query.php
@@ -522,7 +522,7 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa
     }
     else {
       // Validate and set sort parameter
-      $fields = implode('|', array_keys($this->available_sorts));
+      $fields = implode('|', array_map(array($this, 'regexpEscape'), array_keys($this->available_sorts)));
       if (preg_match('/^(?:(' . $fields . ') (asc|desc),?)+$/', $sortstring, $matches)) {
         // We only use the last match.
         $this->solrsort['#name'] = $matches[1];
@@ -532,6 +532,11 @@ class SolrBaseQuery extends SolrFilterSubQuery implements DrupalSolrQueryInterfa
     }
   }
 
+  protected function regexpEscape($string) {
+    //This is probably not 100% correct
+    return preg_replace('/\W/', '\\\\\0', $string);
+  }
+
   public function getAvailableSorts() {
     return $this->available_sorts;
   }
