From 5143c47e0feeff92ac3dabf9277e23c13a6379f0 Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 18 Nov 2015 07:28:40 -0500
Subject: [PATCH] Fix rcube_utils::words_match() to work with mixed/invalid/binary content (T844)

---
 program/lib/Roundcube/rcube_utils.php |   14 ++++++++++----
 1 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/program/lib/Roundcube/rcube_utils.php b/program/lib/Roundcube/rcube_utils.php
index e1b9bdb..7b6e7ba 100644
--- a/program/lib/Roundcube/rcube_utils.php
+++ b/program/lib/Roundcube/rcube_utils.php
@@ -993,12 +993,18 @@
      */
     public static function words_match($haystack, $needle)
     {
-        $a_needle = self::tokenize_string($needle, 1);
-        $haystack = join(" ", self::tokenize_string($haystack, 1));
+        $a_needle  = self::tokenize_string($needle, 1);
+        $_haystack = join(" ", self::tokenize_string($haystack, 1));
+        $valid     = strlen($_haystack) > 0;
+        $hits      = 0;
 
-        $hits = 0;
         foreach ($a_needle as $w) {
-            if (stripos($haystack, $w) !== false) {
+            if ($valid) {
+                if (stripos($_haystack, $w) !== false) {
+                    $hits++;
+                }
+            }
+            else if (stripos($haystack, $w) !== false) {
                 $hits++;
             }
         }

--
Gitblit v1.9.1