From d081b75dccfd4dcb2ce2b28d3c0b9fde4349d455 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 16:25:51 +0900 Subject: [PATCH 01/35] Update search operator to process quotation marks and AND or OR operator --- .../parsers/dbquery/variablebase.php | 47 ++++++++++++++++--- 1 file changed, 40 insertions(+), 7 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 255fcc375..d4af65e19 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,23 +237,56 @@ class VariableBase } break; case 'search': - $keywords = preg_split('/[\s,]+/', $value, 10, \PREG_SPLIT_NO_EMPTY); + $keywords = preg_split('/("[^"]*")|[\s,]+/', $value, 10, \PREG_SPLIT_NO_EMPTY); $conditions = array(); + $operators = array('AND', 'OR', '|'); $placeholders = implode(', ', array_fill(0, count($keywords), '?')); foreach ($keywords as $item) { - if (substr($item, 0, 1) === '-') + // trim quotation mark + if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"') { - $conditions[] = sprintf('%s NOT LIKE ?', $column); - $item = substr($item, 1); + $item = substr($item, 1, -1); + } + elseif (strlen($item) > 3 && (substr($item, 0, 1) === '-') && (substr($item, 1, 1) === substr($item, -1)) && substr($item, -1) === '"') + { + $item = '-' . substr($item, 2, -1); + } + + // pass blank text + if (trim($item) === "") + { + continue; + } + + // process 'AND' or 'OR' operator + if (in_array($item, $operators) + { + if ($item === '|') + { + $item = 'OR'; + } + $conditions[] = sprintf('%s', $item); } else { - $conditions[] = sprintf('%s LIKE ?', $column); + if (substr($item, 0, 1) === '-') + { + $conditions[] = sprintf('%s NOT LIKE ?', $column); + $item = substr($item, 1); + } + else + { + $conditions[] = sprintf('%s LIKE ?', $column); + } + $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; + // if there is no operator, assume 'AND' + $conditions[] = 'AND'; } - $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; } - $conditions = implode(' AND ', $conditions); + // remove the last point (would be an operator) + array_pop($conditions) + $conditions = implode(' ', $conditions); $where = count($keywords) === 1 ? $conditions : "($conditions)"; break; case 'plus': From 83df509d7dda60b6e5f2df85ff142a755d86aa1f Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 16:31:17 +0900 Subject: [PATCH 02/35] =?UTF-8?q?=EB=B9=BC=EB=A8=B9=EC=9D=80=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index d4af65e19..71b40eb5e 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,7 +237,7 @@ class VariableBase } break; case 'search': - $keywords = preg_split('/("[^"]*")|[\s,]+/', $value, 10, \PREG_SPLIT_NO_EMPTY); + $keywords = preg_split('/("[^"]*")|[\s,]+/', $value, 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); $conditions = array(); $operators = array('AND', 'OR', '|'); $placeholders = implode(', ', array_fill(0, count($keywords), '?')); From 0c08e92a54f33390ae723a4b263f583c0aadcdda Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 16:37:49 +0900 Subject: [PATCH 03/35] =?UTF-8?q?=EB=B9=A0=EC=A7=84=20=EA=B4=84=ED=98=B8?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 71b40eb5e..52f0ee2c1 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -260,7 +260,7 @@ class VariableBase } // process 'AND' or 'OR' operator - if (in_array($item, $operators) + if (in_array($item, $operators)) { if ($item === '|') { From a0449a2e0f42f26eb2c09df892cc45efef0c2025 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 16:51:39 +0900 Subject: [PATCH 04/35] =?UTF-8?q?=ED=82=A4=EC=9B=8C=EB=93=9C=20=EC=B2=98?= =?UTF-8?q?=EB=A6=AC=EB=A5=BC=20=EB=B3=84=EB=8F=84=20=ED=95=A8=EC=88=98?= =?UTF-8?q?=EB=A1=9C=20=EB=B6=84=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parsers/dbquery/variablebase.php | 121 ++++++++++-------- 1 file changed, 70 insertions(+), 51 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 52f0ee2c1..76e18e2ef 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,57 +237,9 @@ class VariableBase } break; case 'search': - $keywords = preg_split('/("[^"]*")|[\s,]+/', $value, 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); - $conditions = array(); - $operators = array('AND', 'OR', '|'); - $placeholders = implode(', ', array_fill(0, count($keywords), '?')); - foreach ($keywords as $item) - { - // trim quotation mark - if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"') - { - $item = substr($item, 1, -1); - } - elseif (strlen($item) > 3 && (substr($item, 0, 1) === '-') && (substr($item, 1, 1) === substr($item, -1)) && substr($item, -1) === '"') - { - $item = '-' . substr($item, 2, -1); - } - - // pass blank text - if (trim($item) === "") - { - continue; - } - - // process 'AND' or 'OR' operator - if (in_array($item, $operators)) - { - if ($item === '|') - { - $item = 'OR'; - } - $conditions[] = sprintf('%s', $item); - } - else - { - if (substr($item, 0, 1) === '-') - { - $conditions[] = sprintf('%s NOT LIKE ?', $column); - $item = substr($item, 1); - } - else - { - $conditions[] = sprintf('%s LIKE ?', $column); - } - $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; - // if there is no operator, assume 'AND' - $conditions[] = 'AND'; - } - } - // remove the last point (would be an operator) - array_pop($conditions) - $conditions = implode(' ', $conditions); - $where = count($keywords) === 1 ? $conditions : "($conditions)"; + $parsed_keywords = $this->_parseSearchKeywords($value) + $where = $parsed_keywords->where; + $params = $parsed_keywords->params; break; case 'plus': $where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?'); @@ -477,4 +429,71 @@ class VariableBase throw new \Rhymix\Framework\Exceptions\QueryError('Variable ' . $this->var . ' for column ' . $column . ' must contain no more than ' . $this->minlength . ' characters'); } } + + /** + * Parse the search text. + * + * @param string $value + * @return object + */ + private function _parseSearchKeywords() ($value) + { + // parse the value (text) + $keywords = preg_split('/("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); + $conditions = array(); + + // loop the parsed keywords or operators + foreach ($keywords as $item) + { + // trim quotation mark + if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"') + { + $item = substr($item, 1, -1); + } + elseif (strlen($item) > 3 && (substr($item, 0, 1) === '-') && (substr($item, 1, 1) === substr($item, -1)) && substr($item, -1) === '"') + { + $item = '-' . substr($item, 2, -1); + } + + // pass blank text + if (trim($item) === "") + { + continue; + } + + // process 'AND' or 'OR' operator + if (in_array($item, $operators)) + { + if ($item === '|') + { + $item = 'OR'; + } + $conditions[] = sprintf('%s', $item); + } + else + { + if (substr($item, 0, 1) === '-') + { + $conditions[] = sprintf('%s NOT LIKE ?', $column); + $item = substr($item, 1); + } + else + { + $conditions[] = sprintf('%s LIKE ?', $column); + } + $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; + // if there is no operator, assume 'AND' + $conditions[] = 'AND'; + } + } + // remove the last point (would be an operator) + array_pop($conditions); + $conditions = implode(' ', $conditions); + $where = count($keywords) === 1 ? $conditions : "($conditions)"; + + return (object) array ( + 'where' => $where, + 'params' => $params + ); + } } From 87ef4f1e8eca7e8ae719ef6f04bf76b90252c117 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 16:52:28 +0900 Subject: [PATCH 05/35] =?UTF-8?q?=EB=AC=B8=EC=9E=A5=20=EB=81=9D=20?= =?UTF-8?q?=EC=84=B8=EB=AF=B8=EC=BD=9C=EB=A1=A0=20=EB=B9=A0=EC=A7=84=20?= =?UTF-8?q?=EA=B2=83=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 76e18e2ef..7c8bb6a7d 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,7 +237,7 @@ class VariableBase } break; case 'search': - $parsed_keywords = $this->_parseSearchKeywords($value) + $parsed_keywords = $this->_parseSearchKeywords($value); $where = $parsed_keywords->where; $params = $parsed_keywords->params; break; From 32d734059d9b305d57288630525e63a15363773a Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 16:57:40 +0900 Subject: [PATCH 06/35] =?UTF-8?q?=EB=AC=B8=EB=B2=95=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EA=B4=84=ED=98=B8=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 7c8bb6a7d..3f7bd97e3 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -436,7 +436,7 @@ class VariableBase * @param string $value * @return object */ - private function _parseSearchKeywords() ($value) + private function _parseSearchKeywords($value) { // parse the value (text) $keywords = preg_split('/("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); From edc674a220dd438c4807b832939a16d3241cd733 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 17:10:57 +0900 Subject: [PATCH 07/35] =?UTF-8?q?=EC=B6=9C=EB=A0=A5=20=EA=B0=92=EC=9D=98?= =?UTF-8?q?=20=ED=98=95=EC=8B=9D=EC=9D=84=20=EB=8B=A8=EC=88=9C=ED=95=98?= =?UTF-8?q?=EA=B2=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 3f7bd97e3..e12499041 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -238,8 +238,8 @@ class VariableBase break; case 'search': $parsed_keywords = $this->_parseSearchKeywords($value); - $where = $parsed_keywords->where; - $params = $parsed_keywords->params; + $where = $parsed_keywords[0]; + $params = $parsed_keywords[1]; break; case 'plus': $where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?'); @@ -436,7 +436,7 @@ class VariableBase * @param string $value * @return object */ - private function _parseSearchKeywords($value) + private function _parseSearchKeywords() ($value) { // parse the value (text) $keywords = preg_split('/("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); @@ -491,9 +491,6 @@ class VariableBase $conditions = implode(' ', $conditions); $where = count($keywords) === 1 ? $conditions : "($conditions)"; - return (object) array ( - 'where' => $where, - 'params' => $params - ); + return [$where, $params]; } } From 55651a006a540894f17f09a84ceeed64b8446631 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 17:11:23 +0900 Subject: [PATCH 08/35] =?UTF-8?q?=EB=AC=B8=EB=B2=95=EC=97=90=20=EB=A7=9E?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8A=94=20=EA=B4=84=ED=98=B8=20=EB=8B=A4?= =?UTF-8?q?=EC=8B=9C=20=EC=82=AD=EC=A0=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index e12499041..2dd4908e2 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -436,7 +436,7 @@ class VariableBase * @param string $value * @return object */ - private function _parseSearchKeywords() ($value) + private function _parseSearchKeywords($value) { // parse the value (text) $keywords = preg_split('/("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); From c187da62cbbbce92f91e1ecce12d0455aebf5a03 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 17:21:00 +0900 Subject: [PATCH 09/35] php 8.0 travis ci test --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 951bd0c8e..f7185f004 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ php: - 7.2 - 7.3 - 7.4 + - 8.0 jobs: allow_failures: - php: From 56921fa9bec7e25712625ed639530275010df711 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 18:03:47 +0900 Subject: [PATCH 10/35] =?UTF-8?q?=EA=B4=84=ED=98=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parsers/dbquery/variablebase.php | 29 ++++++++++++++++--- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 2dd4908e2..bc203a93f 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -239,7 +239,7 @@ class VariableBase case 'search': $parsed_keywords = $this->_parseSearchKeywords($value); $where = $parsed_keywords[0]; - $params = $parsed_keywords[1]; + $params = array_merge($params, $parsed_keywords[1]); break; case 'plus': $where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?'); @@ -438,13 +438,27 @@ class VariableBase */ private function _parseSearchKeywords($value) { - // parse the value (text) - $keywords = preg_split('/("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); - $conditions = array(); + // Initialze the return values. + $where = ''; + $params = array(); + // parse the value (text) + $keywords = preg_split('/(\([^\)]*\))|("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); + $conditions = array(); + $operators = array('AND', 'OR', '|'); // loop the parsed keywords or operators foreach ($keywords as $item) { + // treat parenthesis + if (strlen($item) > 2 && substr($item, 0, 1) === '(' && substr($item, -1) === ')') + { + $parsed_keywords = $this->_parseSearchKeywords(substr($item, 1, -1)); + $conditions[] = "(". $parsed_keywords[0] . ")"; + $conditions[] = 'AND'; + $params = array_merge($params, $parsed_keywords[1]); + continue; + } + // trim quotation mark if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"') { @@ -468,6 +482,13 @@ class VariableBase { $item = 'OR'; } + // remove the last point (would be an operator) + $last_condition = array_pop($conditions); + // the last condition might not be an operator. + if (!in_array($last_condition, $operators)) + { + $conditions[] = $last_condition; + } $conditions[] = sprintf('%s', $item); } else From d23c5f727170259a1ee2a791c91bb30dcce9b273 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Tue, 22 Dec 2020 18:05:40 +0900 Subject: [PATCH 11/35] =?UTF-8?q?@kijin=20=EB=8B=98=20=EC=9D=98=EA=B2=AC?= =?UTF-8?q?=EC=97=90=20=EB=94=B0=EB=9D=BC=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index bc203a93f..bc8821559 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,9 +237,7 @@ class VariableBase } break; case 'search': - $parsed_keywords = $this->_parseSearchKeywords($value); - $where = $parsed_keywords[0]; - $params = array_merge($params, $parsed_keywords[1]); + list($where, $params) = $this->_parseSearchKeywords($value); break; case 'plus': $where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?'); @@ -436,7 +434,7 @@ class VariableBase * @param string $value * @return object */ - private function _parseSearchKeywords($value) + protected function _parseSearchKeywords($value) { // Initialze the return values. $where = ''; From a9ff791f4b0177e85dbb94b571fce35836725b00 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 09:18:14 +0900 Subject: [PATCH 12/35] Update variablebase.php --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index bc8821559..340d398e2 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,7 +237,7 @@ class VariableBase } break; case 'search': - list($where, $params) = $this->_parseSearchKeywords($value); + list($where, $params[]) = $this->_parseSearchKeywords($value); break; case 'plus': $where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?'); From 1b80db46522e12e8ad0f607188abf919c65cecd3 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 09:23:26 +0900 Subject: [PATCH 13/35] fix to get the column variable --- common/framework/parsers/dbquery/variablebase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 340d398e2..0f9277634 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,7 +237,7 @@ class VariableBase } break; case 'search': - list($where, $params[]) = $this->_parseSearchKeywords($value); + list($where, $params[]) = $this->_parseSearchKeywords($column, $value); break; case 'plus': $where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?'); @@ -434,7 +434,7 @@ class VariableBase * @param string $value * @return object */ - protected function _parseSearchKeywords($value) + protected function _parseSearchKeywords($column, $value) { // Initialze the return values. $where = ''; From a247ec833589cb94ea3d9c418d5389298496c1e5 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 09:40:57 +0900 Subject: [PATCH 14/35] =?UTF-8?q?$params=EC=97=90=20=EA=B8=B0=EC=A1=B4=20?= =?UTF-8?q?=EA=B0=92=EC=9D=B4=20=EC=9C=A0=EC=A7=80=EB=90=98=EB=8F=84?= =?UTF-8?q?=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 0f9277634..5063d2121 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -237,7 +237,9 @@ class VariableBase } break; case 'search': - list($where, $params[]) = $this->_parseSearchKeywords($column, $value); + $parsed_keywords = $this->_parseSearchKeywords($column, $value); + $where = $parsed_keywords[0]; + $params = array_merge($params, $parsed_keywords[1]); break; case 'plus': $where = sprintf('%s = %s + %s', $column, $column, $is_expression ? $value : '?'); From 46110f0915346f8d4e49777badd7b6c8c9cf82ab Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 09:54:46 +0900 Subject: [PATCH 15/35] Treat quotation mark --- common/framework/parsers/dbquery/variablebase.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 5063d2121..402d65a76 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -442,7 +442,14 @@ class VariableBase $where = ''; $params = array(); - // parse the value (text) + // flag to mark transformed quotation mark. + $escaped_quot = false; + // parse the value (text); + if (strpos ($value, '"')) + { + $escaped_quot = true; + $value = str_replace('"', '"', $value); + } $keywords = preg_split('/(\([^\)]*\))|("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); $conditions = array(); $operators = array('AND', 'OR', '|'); @@ -475,6 +482,12 @@ class VariableBase continue; } + if($escaped_quot === true) + { + $value = str_replace('"', '"', $value); + $escaped_quot = false; + } + // process 'AND' or 'OR' operator if (in_array($item, $operators)) { From 2cb87af7230be3dd765f7e9c4929797b311597f3 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 09:59:54 +0900 Subject: [PATCH 16/35] treat quotation mark2 --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 402d65a76..5ddfb2ec5 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -445,7 +445,7 @@ class VariableBase // flag to mark transformed quotation mark. $escaped_quot = false; // parse the value (text); - if (strpos ($value, '"')) + if (strpos ($value, '"') !== false) { $escaped_quot = true; $value = str_replace('"', '"', $value); From b6698eb5e5ae1c70a84bd6fb05a57ef9b7654b4c Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 10:17:01 +0900 Subject: [PATCH 17/35] Fix input parmameters --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 5ddfb2ec5..2473ec6d2 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -459,7 +459,7 @@ class VariableBase // treat parenthesis if (strlen($item) > 2 && substr($item, 0, 1) === '(' && substr($item, -1) === ')') { - $parsed_keywords = $this->_parseSearchKeywords(substr($item, 1, -1)); + $parsed_keywords = $this->_parseSearchKeywords($column, substr($item, 1, -1)); $conditions[] = "(". $parsed_keywords[0] . ")"; $conditions[] = 'AND'; $params = array_merge($params, $parsed_keywords[1]); From 8e48abd0dbbe26fd2e77d173e4e82f8b92c1bd40 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 10:32:00 +0900 Subject: [PATCH 18/35] =?UTF-8?q?=EC=A3=BC=EC=84=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 2473ec6d2..4b86e2372 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -433,8 +433,9 @@ class VariableBase /** * Parse the search text. * + * @param string $column * @param string $value - * @return object + * @return array */ protected function _parseSearchKeywords($column, $value) { From 51541dde7d6bceb30a85c698fee0d9549488c39d Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 20:30:50 +0900 Subject: [PATCH 19/35] =?UTF-8?q?=ED=86=B5=ED=95=A9=EA=B2=80=EC=83=89=20?= =?UTF-8?q?=EB=AA=A8=EB=93=88=EC=97=90=EC=84=9C=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=96=B4=EA=B0=80=20=EC=9D=B4=EC=A4=91=EC=9C=BC=EB=A1=9C=20esc?= =?UTF-8?q?ape=20=EB=90=98=EB=8A=94=20=EB=AC=B8=EC=A0=9C=20=EC=88=98?= =?UTF-8?q?=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/integration_search/integration_search.view.php | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/integration_search/integration_search.view.php b/modules/integration_search/integration_search.view.php index 2b9ec9b5e..080b79f2e 100644 --- a/modules/integration_search/integration_search.view.php +++ b/modules/integration_search/integration_search.view.php @@ -23,7 +23,7 @@ class integration_searchView extends integration_search * * @return void */ - function init() + public function init() { } @@ -32,7 +32,7 @@ class integration_searchView extends integration_search * * @return Object */ - function IS() + public function IS() { $oFile = getClass('file'); $oModuleModel = getModel('module'); @@ -114,7 +114,8 @@ class integration_searchView extends integration_search // Set a variable for search keyword $is_keyword = Context::get('is_keyword'); - $is_keyword = escape(trim(utf8_normalize_spaces($is_keyword))); + // As the variables from GET or POST will be escaped by setRequestArguments method at Context class, the double_escape variable should be "FALSE", and also the escape function might be useful when this method was called from the other way (for not escaped keyword). + $is_keyword = escape(trim(utf8_normalize_spaces($is_keyword)), false); if (mb_strlen($is_keyword, 'UTF-8') > 40) { $is_keyword = mb_substr($is_keyword, 0, 40); From b4f1f72ed54f65ba32393f939f6de4385b24efcb Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 21:08:54 +0900 Subject: [PATCH 20/35] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=97=90=20=EB=9D=BC=EC=9D=B4=EB=AF=B9=EC=8A=A4=20operator=20?= =?UTF-8?q?=EC=A0=81=EC=9A=A9=20=EB=93=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/file/file.admin.model.php | 20 ++++++++++---------- modules/file/queries/getFileList.xml | 8 ++++---- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/modules/file/file.admin.model.php b/modules/file/file.admin.model.php index 1bb074c63..b164d5458 100644 --- a/modules/file/file.admin.model.php +++ b/modules/file/file.admin.model.php @@ -10,7 +10,7 @@ class fileAdminModel extends file * Initialization * @return void */ - function init() + public function init() { } @@ -62,7 +62,7 @@ class fileAdminModel extends file * @param array $columnList Column list to get from DB * @return Object Object contains query result */ - function getFileList($obj, $columnList = array()) + public function getFileList($obj, $columnList = array()) { $args = new stdClass(); $this->_makeSearchParam($obj, $args); @@ -75,9 +75,9 @@ class fileAdminModel extends file elseif($obj->direct_download == 'N') $args->direct_download= 'N'; // Set variables $args->sort_index = $obj->sort_index; - $args->page = $obj->page?$obj->page:1; - $args->list_count = $obj->list_count?$obj->list_count:20; - $args->page_count = $obj->page_count?$obj->page_count:10; + $args->page = $obj->page?? 1; + $args->list_count = $obj->list_count?? 20; + $args->page_count = $obj->page_count?? 10; $args->s_module_srl = $obj->module_srl; $args->exclude_module_srl = $obj->exclude_module_srl; if(toBool($obj->exclude_secret)) @@ -124,7 +124,7 @@ class fileAdminModel extends file * @param object $obj Search options (not used...) * @return array */ - function getFilesCountByGroupValid($obj = '') + public function getFilesCountByGroupValid($obj = '') { //$this->_makeSearchParam($obj, $args); @@ -138,7 +138,7 @@ class fileAdminModel extends file * @param string $date Date string * @return int */ - function getFilesCountByDate($date = '') + public function getFilesCountByDate($date = '') { $args = new stdClass(); if($date) @@ -162,11 +162,11 @@ class fileAdminModel extends file * @param object $args Result searach options * @return void */ - function _makeSearchParam(&$obj, &$args) + protected function _makeSearchParam(&$obj, &$args) { // Search options - $search_target = $obj->search_target?$obj->search_target:trim(Context::get('search_target')); - $search_keyword = $obj->search_keyword?$obj->search_keyword:trim(Context::get('search_keyword')); + $search_target = $obj->search_target ?? trim(Context::get('search_target')); + $search_keyword = $obj->search_keyword ?? trim(Context::get('search_keyword')); if($search_target && $search_keyword) { diff --git a/modules/file/queries/getFileList.xml b/modules/file/queries/getFileList.xml index 9faf6fb1e..43461e9fd 100644 --- a/modules/file/queries/getFileList.xml +++ b/modules/file/queries/getFileList.xml @@ -20,15 +20,15 @@ - + - - - + + + From ce63a69952c21cbeb603225eaa0d8826c2c16ef1 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 21:16:52 +0900 Subject: [PATCH 21/35] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=8B=9C=EC=97=90=EB=8F=84=20'search'=20operator=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/file/queries/getFileListByTargetStatus.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/file/queries/getFileListByTargetStatus.xml b/modules/file/queries/getFileListByTargetStatus.xml index 7092da25f..999d87e02 100644 --- a/modules/file/queries/getFileListByTargetStatus.xml +++ b/modules/file/queries/getFileListByTargetStatus.xml @@ -1,4 +1,4 @@ - +
@@ -35,15 +35,15 @@ - + - - - + + + From 75b0740bd80f20f5c1907c78ad26be342a6997b6 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 21:46:28 +0900 Subject: [PATCH 22/35] =?UTF-8?q?=ED=8C=8C=EC=9D=BC=20=EC=9D=B4=EB=A6=84?= =?UTF-8?q?=20=EA=B2=80=EC=83=89=EC=8B=9C=EC=97=90=EB=8F=84=20search=20ope?= =?UTF-8?q?rator=EB=A5=BC=20=EC=82=AC=EC=9A=A9=ED=95=98=EB=8F=84=EB=A1=9D?= =?UTF-8?q?=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/file/file.admin.model.php | 1 - modules/file/queries/getFilesCountByGroupValid.xml | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/modules/file/file.admin.model.php b/modules/file/file.admin.model.php index b164d5458..89daed2bc 100644 --- a/modules/file/file.admin.model.php +++ b/modules/file/file.admin.model.php @@ -173,7 +173,6 @@ class fileAdminModel extends file switch($search_target) { case 'filename' : - if($search_keyword) $search_keyword = str_replace(' ','%',$search_keyword); $args->s_filename = $search_keyword; break; case 'filesize_more' : diff --git a/modules/file/queries/getFilesCountByGroupValid.xml b/modules/file/queries/getFilesCountByGroupValid.xml index 869d7a3fd..509a4d0c6 100644 --- a/modules/file/queries/getFilesCountByGroupValid.xml +++ b/modules/file/queries/getFilesCountByGroupValid.xml @@ -1,4 +1,4 @@ - +
@@ -12,7 +12,7 @@ - + From ae71a4569168ee13877d5b6bb8dae0246f8df917 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Wed, 23 Dec 2020 21:52:51 +0900 Subject: [PATCH 23/35] =?UTF-8?q?=EC=9D=98=EB=AF=B8=EA=B0=80=20=EB=8B=AC?= =?UTF-8?q?=EB=9D=BC=EC=A7=80=EB=8A=94=20=EB=B6=80=EB=B6=84=20=EC=9E=AC?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/file/file.admin.model.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/file/file.admin.model.php b/modules/file/file.admin.model.php index 89daed2bc..ba615727d 100644 --- a/modules/file/file.admin.model.php +++ b/modules/file/file.admin.model.php @@ -75,9 +75,9 @@ class fileAdminModel extends file elseif($obj->direct_download == 'N') $args->direct_download= 'N'; // Set variables $args->sort_index = $obj->sort_index; - $args->page = $obj->page?? 1; - $args->list_count = $obj->list_count?? 20; - $args->page_count = $obj->page_count?? 10; + $args->page = $obj->page?$obj->page:1; + $args->list_count = $obj->list_count?$obj->list_count:20; + $args->page_count = $obj->page_count?$obj->page_count:10; $args->s_module_srl = $obj->module_srl; $args->exclude_module_srl = $obj->exclude_module_srl; if(toBool($obj->exclude_secret)) @@ -165,8 +165,8 @@ class fileAdminModel extends file protected function _makeSearchParam(&$obj, &$args) { // Search options - $search_target = $obj->search_target ?? trim(Context::get('search_target')); - $search_keyword = $obj->search_keyword ?? trim(Context::get('search_keyword')); + $search_target = $obj->search_target?$obj->search_target:trim(Context::get('search_target')); + $search_keyword = $obj->search_keyword?$obj->search_keyword:trim(Context::get('search_keyword')); if($search_target && $search_keyword) { From e86b2ec311cb28fc2147f611bab7b1d2a10454f3 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Fri, 25 Dec 2020 18:20:44 +0900 Subject: [PATCH 24/35] =?UTF-8?q?=EB=94=B0=EC=98=B4=ED=91=9C=20=EB=82=B4?= =?UTF-8?q?=EC=9D=98=20=EB=B9=BC=EA=B8=B0=20=EA=B8=B0=ED=98=B8=EB=8A=94=20?= =?UTF-8?q?=EC=9D=98=EB=AF=B8=EB=A5=BC=20=EB=B6=80=EC=97=AC=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 4b86e2372..b1f390ca7 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -445,6 +445,10 @@ class VariableBase // flag to mark transformed quotation mark. $escaped_quot = false; + + // flag to mark escaped hypen in the quotation block + $escaped_hyphen = false; + // parse the value (text); if (strpos ($value, '"') !== false) { @@ -471,6 +475,10 @@ class VariableBase if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"') { $item = substr($item, 1, -1); + if (substr($item, 0, 1) === '-') + { + $escaped_hyphen = true; + } } elseif (strlen($item) > 3 && (substr($item, 0, 1) === '-') && (substr($item, 1, 1) === substr($item, -1)) && substr($item, -1) === '"') { @@ -507,7 +515,7 @@ class VariableBase } else { - if (substr($item, 0, 1) === '-') + if (substr($item, 0, 1) === '-' && $escaped_hyphen !== true) { $conditions[] = sprintf('%s NOT LIKE ?', $column); $item = substr($item, 1); @@ -516,7 +524,7 @@ class VariableBase { $conditions[] = sprintf('%s LIKE ?', $column); } - $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; + $params[] = '%' . str_replace(['\\', '_', '%', '-'], ['\\\\', '\_', '\%', '\-'], $item) . '%'; // if there is no operator, assume 'AND' $conditions[] = 'AND'; } From 510d1671bee7794289442292764adf3cc56c3200 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Fri, 25 Dec 2020 21:31:48 +0900 Subject: [PATCH 25/35] =?UTF-8?q?=ED=8C=8C=EB=9D=BC=EB=AF=B8=ED=84=B0=20es?= =?UTF-8?q?cape=20=EB=AA=A9=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index b1f390ca7..92a7fbe9f 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -524,7 +524,7 @@ class VariableBase { $conditions[] = sprintf('%s LIKE ?', $column); } - $params[] = '%' . str_replace(['\\', '_', '%', '-'], ['\\\\', '\_', '\%', '\-'], $item) . '%'; + $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; // if there is no operator, assume 'AND' $conditions[] = 'AND'; } From 09def40ee0e5409e37a526d3b2a54d3f468e38de Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Fri, 25 Dec 2020 21:55:08 +0900 Subject: [PATCH 26/35] =?UTF-8?q?=EB=94=B0=EC=98=B4=ED=91=9C=EB=A1=9C=20?= =?UTF-8?q?=EB=AC=B6=EC=9D=B8=20=EA=B5=AC=EB=AC=B8=EB=8F=84=20NOT=20LIKE?= =?UTF-8?q?=20=EA=B0=80=20=EA=B0=80=EB=8A=A5=ED=95=98=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 92a7fbe9f..e9abf65e2 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -455,7 +455,7 @@ class VariableBase $escaped_quot = true; $value = str_replace('"', '"', $value); } - $keywords = preg_split('/(\([^\)]*\))|("[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); + $keywords = preg_split('/(\([^\)]*\))|(\-?"[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); $conditions = array(); $operators = array('AND', 'OR', '|'); // loop the parsed keywords or operators From 1bb569c84b0180970e80618fe58b956ac1987d39 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sat, 26 Dec 2020 09:27:05 +0900 Subject: [PATCH 27/35] =?UTF-8?q?=EB=84=88=EB=AC=B4=20=EB=A7=8E=EC=9D=80?= =?UTF-8?q?=20=EB=AC=B8=EC=A0=9C=20=EC=88=98=EC=A0=95.=20`too=20much=20pro?= =?UTF-8?q?blems`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index e9abf65e2..2d6f94947 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -465,7 +465,7 @@ class VariableBase if (strlen($item) > 2 && substr($item, 0, 1) === '(' && substr($item, -1) === ')') { $parsed_keywords = $this->_parseSearchKeywords($column, substr($item, 1, -1)); - $conditions[] = "(". $parsed_keywords[0] . ")"; + $conditions[] = $parsed_keywords[0]; $conditions[] = 'AND'; $params = array_merge($params, $parsed_keywords[1]); continue; @@ -511,7 +511,7 @@ class VariableBase { $conditions[] = $last_condition; } - $conditions[] = sprintf('%s', $item); + $conditions[] = $item; } else { From 9e847dadcb007127635f65ecc359981672c8a15d Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 19:44:18 +0900 Subject: [PATCH 28/35] code refining! --- .../parsers/dbquery/variablebase.php | 66 ++++++++----------- 1 file changed, 26 insertions(+), 40 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 2d6f94947..c93c91ea5 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -450,11 +450,7 @@ class VariableBase $escaped_hyphen = false; // parse the value (text); - if (strpos ($value, '"') !== false) - { - $escaped_quot = true; - $value = str_replace('"', '"', $value); - } + $value = str_replace('"', '"', $value); $keywords = preg_split('/(\([^\)]*\))|(\-?"[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); $conditions = array(); $operators = array('AND', 'OR', '|'); @@ -462,41 +458,19 @@ class VariableBase foreach ($keywords as $item) { // treat parenthesis - if (strlen($item) > 2 && substr($item, 0, 1) === '(' && substr($item, -1) === ')') + if (substr($item, 0, 1) === '(' && substr($item, -1) === ')') { - $parsed_keywords = $this->_parseSearchKeywords($column, substr($item, 1, -1)); - $conditions[] = $parsed_keywords[0]; - $conditions[] = 'AND'; - $params = array_merge($params, $parsed_keywords[1]); - continue; - } - - // trim quotation mark - if (strlen($item) > 2 && (substr($item, 0, 1) === substr($item, -1)) && substr($item, -1) === '"') - { - $item = substr($item, 1, -1); - if (substr($item, 0, 1) === '-') + $item = trim(substr($item, 1, -1)); + if ( $item !== "" ) { - $escaped_hyphen = true; + $parsed_keywords = $this->_parseSearchKeywords($column, substr($item, 1, -1)); + $conditions[] = $parsed_keywords[0]; + $conditions[] = 'AND'; + $params = array_merge($params, $parsed_keywords[1]); } - } - elseif (strlen($item) > 3 && (substr($item, 0, 1) === '-') && (substr($item, 1, 1) === substr($item, -1)) && substr($item, -1) === '"') - { - $item = '-' . substr($item, 2, -1); - } - - // pass blank text - if (trim($item) === "") - { continue; } - if($escaped_quot === true) - { - $value = str_replace('"', '"', $value); - $escaped_quot = false; - } - // process 'AND' or 'OR' operator if (in_array($item, $operators)) { @@ -505,16 +479,13 @@ class VariableBase $item = 'OR'; } // remove the last point (would be an operator) - $last_condition = array_pop($conditions); - // the last condition might not be an operator. - if (!in_array($last_condition, $operators)) - { - $conditions[] = $last_condition; - } + array_pop($conditions); $conditions[] = $item; } else { + $value = str_replace('"', '"', $value); + if (substr($item, 0, 1) === '-' && $escaped_hyphen !== true) { $conditions[] = sprintf('%s NOT LIKE ?', $column); @@ -524,6 +495,21 @@ class VariableBase { $conditions[] = sprintf('%s LIKE ?', $column); } + + // trim quotation mark + if (substr($item, 0, 6) === substr($item, -6) && substr($item, -6) === '"') + { + $item = substr($item, 6, -6); + + } + + // pass blank text + if (trim($item) === "") + { + array_pop($conditions); + continue; + } + $params[] = '%' . str_replace(['\\', '_', '%'], ['\\\\', '\_', '\%'], $item) . '%'; // if there is no operator, assume 'AND' $conditions[] = 'AND'; From 21bf8cdaca359a96e26a4960a60ce56d055b37bb Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 19:54:28 +0900 Subject: [PATCH 29/35] code refining2 --- common/framework/parsers/dbquery/variablebase.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index c93c91ea5..52a0793cc 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -451,7 +451,7 @@ class VariableBase // parse the value (text); $value = str_replace('"', '"', $value); - $keywords = preg_split('/(\([^\)]*\))|(\-?"[^"]*")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); + $keywords = preg_split('/(\([^\)]*\))|(\-?\"[^\"]*\")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); $conditions = array(); $operators = array('AND', 'OR', '|'); // loop the parsed keywords or operators @@ -484,9 +484,9 @@ class VariableBase } else { - $value = str_replace('"', '"', $value); + $item = str_replace('"', '"', $item); - if (substr($item, 0, 1) === '-' && $escaped_hyphen !== true) + if (substr($item, 0, 1) === '-') { $conditions[] = sprintf('%s NOT LIKE ?', $column); $item = substr($item, 1); @@ -500,7 +500,6 @@ class VariableBase if (substr($item, 0, 6) === substr($item, -6) && substr($item, -6) === '"') { $item = substr($item, 6, -6); - } // pass blank text From 86b8664862215c02f75743624b81429eb15e40b7 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 20:34:42 +0900 Subject: [PATCH 30/35] =?UTF-8?q?=ED=95=84=EC=9A=94=20=EC=97=86=EC=96=B4?= =?UTF-8?q?=EC=A7=84=20flag=20=EC=A0=9C=EA=B1=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 6 ------ 1 file changed, 6 deletions(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 52a0793cc..616adde08 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -443,12 +443,6 @@ class VariableBase $where = ''; $params = array(); - // flag to mark transformed quotation mark. - $escaped_quot = false; - - // flag to mark escaped hypen in the quotation block - $escaped_hyphen = false; - // parse the value (text); $value = str_replace('"', '"', $value); $keywords = preg_split('/(\([^\)]*\))|(\-?\"[^\"]*\")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); From 96fde908ba52c9ee450363ab62e167ccc531675c Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 20:58:37 +0900 Subject: [PATCH 31/35] =?UTF-8?q?=EC=A0=95=EA=B7=9C=20=ED=91=9C=ED=98=84?= =?UTF-8?q?=EC=8B=9D=20=EB=8B=A4=EB=93=AC=EA=B8=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- common/framework/parsers/dbquery/variablebase.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/framework/parsers/dbquery/variablebase.php b/common/framework/parsers/dbquery/variablebase.php index 616adde08..b4ad94dc9 100644 --- a/common/framework/parsers/dbquery/variablebase.php +++ b/common/framework/parsers/dbquery/variablebase.php @@ -445,7 +445,7 @@ class VariableBase // parse the value (text); $value = str_replace('"', '"', $value); - $keywords = preg_split('/(\([^\)]*\))|(\-?\"[^\"]*\")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); + $keywords = preg_split('/(\([^\)]*?\))|(\-?\"[^\"]*?\")|[\s,]+/', trim($value), 10, \PREG_SPLIT_NO_EMPTY | \PREG_SPLIT_DELIM_CAPTURE); $conditions = array(); $operators = array('AND', 'OR', '|'); // loop the parsed keywords or operators From 3ff91018cc5ad371d71368ecb7c5940e912d0d87 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 21:14:51 +0900 Subject: [PATCH 32/35] =?UTF-8?q?Add=20unit=20test=20+=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=EA=B2=80=EC=83=89=20=ED=82=A4=EC=9B=8C=EB=93=9C=20?= =?UTF-8?q?=EA=B8=80=EC=9E=90=20=EC=88=98=20=EC=A0=9C=ED=95=9C=20=EB=B3=80?= =?UTF-8?q?=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../integration_search.view.php | 4 ++-- tests/_data/dbquery/selectTest3.xml | 24 +++++++++++++++++++ .../framework/parsers/DBQueryParserTest.php | 14 +++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 tests/_data/dbquery/selectTest3.xml diff --git a/modules/integration_search/integration_search.view.php b/modules/integration_search/integration_search.view.php index 2b9ec9b5e..1add46f55 100644 --- a/modules/integration_search/integration_search.view.php +++ b/modules/integration_search/integration_search.view.php @@ -115,9 +115,9 @@ class integration_searchView extends integration_search // Set a variable for search keyword $is_keyword = Context::get('is_keyword'); $is_keyword = escape(trim(utf8_normalize_spaces($is_keyword))); - if (mb_strlen($is_keyword, 'UTF-8') > 40) + if (mb_strlen($is_keyword, 'UTF-8') > 250) { - $is_keyword = mb_substr($is_keyword, 0, 40); + $is_keyword = mb_substr($is_keyword, 0, 250); } // Set page variables diff --git a/tests/_data/dbquery/selectTest3.xml b/tests/_data/dbquery/selectTest3.xml new file mode 100644 index 000000000..1f30ace49 --- /dev/null +++ b/tests/_data/dbquery/selectTest3.xml @@ -0,0 +1,24 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + diff --git a/tests/unit/framework/parsers/DBQueryParserTest.php b/tests/unit/framework/parsers/DBQueryParserTest.php index 736765375..02c2c2d57 100644 --- a/tests/unit/framework/parsers/DBQueryParserTest.php +++ b/tests/unit/framework/parsers/DBQueryParserTest.php @@ -70,6 +70,20 @@ class DBQueryParserTest extends \Codeception\TestCase\Test $this->assertEquals([20, '20201021'], $params); } + public function testSelectWithSearch() + { + $query = Rhymix\Framework\Parsers\DBQueryParser::loadXML(\RX_BASEDIR . 'tests/_data/dbquery/selectTest3.xml'); + $args = array('division' => 1234, 'last_division' => 4567, 's_title' => '"I love you" -"I hate you"', 's_content' => '"I love you" -"I hate you"', 'page' => 3); + $sql = $query->getQueryString('rx_', $args); + $params = $query->getQueryParams(); + + $this->assertEquals('SELECT DISTINCT * FROM `rx_documents` AS `documents` ' . + 'WHERE (`list_order` >= ? AND `list_order` < ?) AND ' . + '((`title` LIKE ? AND `title` NOT LIKE ?) OR (`content` LIKE ? AND `content` NOT LIKE ?)) AND ' . + 'ORDER BY `list_order` ASC LIMIT 40, 20', $sql); + $this->assertEquals(['1234', '4567', 'I love you', 'I hate you', 'I love you', 'I hate you'], $params); + } + public function testJoin1() { $query = Rhymix\Framework\Parsers\DBQueryParser::loadXML(\RX_BASEDIR . 'tests/_data/dbquery/selectJoinTest1.xml'); From b3abdfd696ed8958126b43d3c459f80462f04056 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 21:18:55 +0900 Subject: [PATCH 33/35] =?UTF-8?q?Unit=20test=20=EC=98=A4=ED=83=80=20?= =?UTF-8?q?=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 맨 마지막 AND는 제거되는 것이 의도가 맞음. - Distinct가 없는 예시. --- tests/unit/framework/parsers/DBQueryParserTest.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/framework/parsers/DBQueryParserTest.php b/tests/unit/framework/parsers/DBQueryParserTest.php index 02c2c2d57..ab529cbb0 100644 --- a/tests/unit/framework/parsers/DBQueryParserTest.php +++ b/tests/unit/framework/parsers/DBQueryParserTest.php @@ -77,9 +77,9 @@ class DBQueryParserTest extends \Codeception\TestCase\Test $sql = $query->getQueryString('rx_', $args); $params = $query->getQueryParams(); - $this->assertEquals('SELECT DISTINCT * FROM `rx_documents` AS `documents` ' . + $this->assertEquals('SELECT * FROM `rx_documents` AS `documents` ' . 'WHERE (`list_order` >= ? AND `list_order` < ?) AND ' . - '((`title` LIKE ? AND `title` NOT LIKE ?) OR (`content` LIKE ? AND `content` NOT LIKE ?)) AND ' . + '((`title` LIKE ? AND `title` NOT LIKE ?) OR (`content` LIKE ? AND `content` NOT LIKE ?)) ' . 'ORDER BY `list_order` ASC LIMIT 40, 20', $sql); $this->assertEquals(['1234', '4567', 'I love you', 'I hate you', 'I love you', 'I hate you'], $params); } From dc5296f326099827f23f481dafa57023b1a475eb Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 21:21:24 +0900 Subject: [PATCH 34/35] =?UTF-8?q?Unit=20test=20=EC=88=98=EC=A0=95.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 키워드 양쪽에 wild-card가 붙는 것이 의도 된 것이 맞음.. --- tests/unit/framework/parsers/DBQueryParserTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/framework/parsers/DBQueryParserTest.php b/tests/unit/framework/parsers/DBQueryParserTest.php index ab529cbb0..560fcb140 100644 --- a/tests/unit/framework/parsers/DBQueryParserTest.php +++ b/tests/unit/framework/parsers/DBQueryParserTest.php @@ -81,7 +81,7 @@ class DBQueryParserTest extends \Codeception\TestCase\Test 'WHERE (`list_order` >= ? AND `list_order` < ?) AND ' . '((`title` LIKE ? AND `title` NOT LIKE ?) OR (`content` LIKE ? AND `content` NOT LIKE ?)) ' . 'ORDER BY `list_order` ASC LIMIT 40, 20', $sql); - $this->assertEquals(['1234', '4567', 'I love you', 'I hate you', 'I love you', 'I hate you'], $params); + $this->assertEquals(['1234', '4567', '%I love you%', '%I hate you%', '%I love you%', '%I hate you%'], $params); } public function testJoin1() From c96b1ee46180c3307dcdc22ee99c05150ad5bbb5 Mon Sep 17 00:00:00 2001 From: Min-Soo Kim Date: Sun, 27 Dec 2020 21:29:07 +0900 Subject: [PATCH 35/35] Revert "Merge branch 'temp_testing' into db-search-operator" This reverts commit c230dffc87fd78da56e97936ab65391dee0a3718, reversing changes made to f8ed3b49f2e193a267ed06c114511c411ac84a75. --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index f7185f004..951bd0c8e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,6 @@ php: - 7.2 - 7.3 - 7.4 - - 8.0 jobs: allow_failures: - php: