Просмотр исходного кода

Fix WHERE ... LIKE ... for SQLite

https://github.com/forkbb/forkbb/pull/10
Visman 3 лет назад
Родитель
Сommit
a71cb56039
3 измененных файлов с 6 добавлено и 6 удалено
  1. 2 2
      app/Models/BanList/Filter.php
  2. 2 2
      app/Models/Search/Execute.php
  3. 2 2
      app/Models/User/Filter.php

+ 2 - 2
app/Models/BanList/Filter.php

@@ -54,8 +54,8 @@ class Filter extends Method
                     if (false !== \strpos($rule[1], '*')) {
                         // кроме * есть другие символы
                         if ('' != \trim($rule[1], '*')) {
-                            $where[] = "b.{$field} LIKE ?{$fields[$field]}";
-                            $vars[]  = \str_replace(['%', '*', '_'], ['\\%', '%', '\\_'], $rule[1]);
+                            $where[] = "b.{$field} LIKE ?{$fields[$field]} ESCAPE '#'";
+                            $vars[]  = \str_replace(['#', '%', '_', '*'], ['##', '#%', '#_', '%'], $rule[1]);
                         }
                         break;
                     }

+ 2 - 2
app/Models/Search/Execute.php

@@ -223,8 +223,8 @@ class Execute extends Method
         //???? что делать с подчеркиванием в именах?
         if ('*' !== $v->author) {
             $usePIdx                 = true;
-            $vars[':author']         = \str_replace(['*', '?'], ['%', '_'], $v->author);
-            $whereIdx[]              = 'p.poster LIKE ?s:author';
+            $vars[':author']         = \str_replace(['#', '_', '*', '?'], ['##', '#_', '%', '_'], $v->author);
+            $whereIdx[]              = 'p.poster LIKE ?s:author ESCAPE \'#\'';
         }
 
         $this->model->showAs         = $v->show_as;

+ 2 - 2
app/Models/User/Filter.php

@@ -54,8 +54,8 @@ class Filter extends Action
                     if (false !== \strpos($rule[1], '*')) {
                         // кроме * есть другие символы
                         if ('' != \trim($rule[1], '*')) {
-                            $where[] = "u.{$field} LIKE ?{$fields[$field]}";
-                            $vars[]  = \str_replace(['%', '*', '_'], ['\\%', '%', '\\_'], $rule[1]);
+                            $where[] = "u.{$field} LIKE ?{$fields[$field]} ESCAPE '#'";
+                            $vars[]  = \str_replace(['#', '%', '_', '*'], ['##', '#%', '#_', '%'], $rule[1]);
                         }
                         break;
                     }