From e2de07d3b641e437ac18f49ba9b62de5b49aba93 Mon Sep 17 00:00:00 2001 From: DariusIII Date: Tue, 6 Feb 2018 15:50:20 +0100 Subject: [PATCH] Update SphinxSearch class --- Changelog | 1 + nntmux/SphinxSearch.php | 30 +++++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/Changelog b/Changelog index fb4b64fca..3aa9ec8cb 100755 --- a/Changelog +++ b/Changelog @@ -1,4 +1,5 @@ 2018-02-06 DariusIII + * Chg: Update SphinxSearch class * Fix: Update installation console commands to fix missing type error when using fixtures in production 2018-02-04 DariusIII * Fix: Fix error on details page in Gamma theme diff --git a/nntmux/SphinxSearch.php b/nntmux/SphinxSearch.php index 0cde3546e..ea6ca1aef 100755 --- a/nntmux/SphinxSearch.php +++ b/nntmux/SphinxSearch.php @@ -14,6 +14,8 @@ class SphinxSearch /** * Establish connection to SphinxQL. + * + * @throws \Exception */ public function __construct() { @@ -49,10 +51,10 @@ class SphinxSearch sprintf( 'REPLACE INTO releases_rt (id, name, searchname, fromname, filename) VALUES (%d, %s, %s, %s, %s)', $parameters['id'], - $this->sphinxQL->escapeString($parameters['name']), - $this->sphinxQL->escapeString($parameters['searchname']), - $this->sphinxQL->escapeString($parameters['fromname']), - empty($parameters['filename']) ? "''" : $this->sphinxQL->escapeString($parameters['filename']) + $this->escapeString($parameters['name']), + $this->escapeString($parameters['searchname']), + $this->escapeString($parameters['fromname']), + empty($parameters['filename']) ? "''" : $this->escapeString($parameters['filename']) ) ); } @@ -81,22 +83,16 @@ class SphinxSearch } /** - * @param $string + * Escapes characters that are treated as special operators by the query language parser * - * @return mixed + * @param string $string unescaped string + * + * @return string Escaped string. */ - public static function escapeString($string) + public function escapeString($string): string { - $from = [ - '\\', '(', ')', '|', '---', '--', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=', "'", - "\x00", "\n", "\r", "\x1a", - ]; - $to = [ - '\\\\\\\\', '\\\\\\\\(', '\\\\\\\\)', '\\\\\\\\|', '-', '-', '\\\\\\\\-', '\\\\\\\\!', - '\\\\\\\\@', '\\\\\\\\~', - '\\\\\\\\"', '\\\\\\\\&', '\\\\\\\\/', '\\\\\\\\^', '\\\\\\\\$', '\\\\\\\\=', "\\'", - '\\x00', '\\n', '\\r', '\\x1a', - ]; + $from = ['\\', '(', ')', '|', '-', '!', '@', '~', '"', '&', '/', '^', '$', '=']; + $to = ['\\\\', '\(', '\)', '\|', '\-', '\!', '\@', '\~', '\"', '\&', '\/', '\^', '\$', '\=']; return str_replace($from, $to, $string); }