From 17dec12670dbbc6ebbd8fc4d2d588862a620eb3b Mon Sep 17 00:00:00 2001 From: Benn Oshrin Date: Sun, 3 Oct 2021 11:38:01 -0400 Subject: [PATCH] Better detection of misconfigured searches (CO-1771) --- app/src/Lib/Match/MatchService.php | 15 +++++++++++++++ app/src/Model/Table/RulesTable.php | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/app/src/Lib/Match/MatchService.php b/app/src/Lib/Match/MatchService.php index c64433b43..41dc18157 100644 --- a/app/src/Lib/Match/MatchService.php +++ b/app/src/Lib/Match/MatchService.php @@ -583,6 +583,11 @@ protected function search(string $mode, // how we handle all this switch($ruleattr->search_type) { case SearchTypeEnum::Distance: + if(empty($attribute->search_distance)) { + // We're configured for search distance but we don't have a value + Log::write('debug', $sor . "/" . $sorid . " No search distance configured for attribute " . $attribute->name . ", skipping rule " . $rule->name); + continue 2; + } $maxdistance = (int)($attribute->search_distance)+1; $attrclause = "LEVENSHTEIN_LESS_EQUAL(" . $colclause @@ -595,6 +600,11 @@ protected function search(string $mode, $attrclause = $colclause . "=?"; break; case SearchTypeEnum::Mapping: + if(empty($attribute->attribute_map_id)) { + // We're configured for attribute mapping, but we don't have a Map + Log::write('debug', $sor . "/" . $sorid . " No Attribute Map configured for attribute " . $attribute->name . ", skipping rule " . $rule->name); + continue 2; + } $qclause = (!$attribute->case_sensitive ? "LOWER(query)" : "query"); $attrclause = "(" . $colclause . " IN (SELECT value @@ -606,6 +616,11 @@ protected function search(string $mode, $attrSql['vals'][$ruleattr->attribute->id][] = (!$attribute->case_sensitive ? strtolower($val) : $val); break; case SearchTypeEnum::Substring: + if(empty($attribute->search_substr_from) || empty($attribute->search_substr_for)) { + // We're configured for substring search but we don't have a value + Log::write('debug', $sor . "/" . $sorid . " Substring search values not properly configured for attribute " . $attribute->name . ", skipping rule " . $rule->name); + continue 2; + } $attrclause = "SUBSTRING(" . $colclause . " FROM " diff --git a/app/src/Model/Table/RulesTable.php b/app/src/Model/Table/RulesTable.php index 6cd173f32..7d7130db5 100644 --- a/app/src/Model/Table/RulesTable.php +++ b/app/src/Model/Table/RulesTable.php @@ -117,7 +117,7 @@ public function validationDefault(Validator $validator): Validator { 'content', [ 'rule' => 'isInteger' ] ); - $validator->allowEmpty('ordr'); + $validator->allowEmptyString('ordr'); return $validator; }