From 4bfca795ab4fada53cea826d55fb8808ee1fb952 Mon Sep 17 00:00:00 2001
From: Demian Katz <demian.katz@villanova.edu>
Date: Fri, 30 Aug 2013 12:55:33 -0400
Subject: [PATCH] Advanced query detection is now more backslash-aware.
 Resolves VUFIND-601.

---
 .../src/VuFindSearch/Backend/Solr/QueryBuilder.php         | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
index 8d8bd87ff22..f3ebb5ba45a 100644
--- a/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
+++ b/module/VuFindSearch/src/VuFindSearch/Backend/Solr/QueryBuilder.php
@@ -225,12 +225,13 @@ class QueryBuilder implements QueryBuilderInterface
         $searchString = preg_replace('/"[^"]*"/', 'quoted', $searchString);
 
         // Check for field specifiers:
-        if (preg_match("/[^\s]\:[^\s]/", $searchString)) {
+        if (preg_match("/[^\s\\\]\:[^\s]/", $searchString)) {
             return true;
         }
 
-        // Check for parentheses and range operators:
-        if (strstr($searchString, '(') && strstr($searchString, ')')) {
+        // Check for unescaped parentheses:
+        $stripped = str_replace(array('\(', '\)'), '', $searchString);
+        if (strstr($stripped, '(') && strstr($stripped, ')')) {
             return true;
         }
         $rangeReg = self::SOLR_RANGE_RE;
-- 
GitLab