Skip to content

Commit 4004e64

Browse files
committed
Merge branch '6.x' of https://github.com/craftcms/feed-me into 6.x
2 parents 3f458d7 + 3ed0335 commit 4004e64

File tree

9 files changed

+38
-11
lines changed

9 files changed

+38
-11
lines changed

src/fields/CalendarEvents.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use craft\feedme\base\FieldInterface;
99
use craft\feedme\helpers\DataHelper;
1010
use craft\feedme\Plugin;
11-
use craft\helpers\Db;
1211
use craft\helpers\Json;
1312
use Solspace\Calendar\Elements\Event as EventElement;
1413

@@ -125,7 +124,8 @@ public function parseField(): mixed
125124
$criteria['status'] = null;
126125
$criteria['typeId'] = $typeIds;
127126
$criteria['limit'] = $limit;
128-
$criteria[$match] = Db::escapeParam($dataValue);
127+
// prep the $dataValue for matching
128+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
129129

130130
Craft::configure($query, $criteria);
131131

src/fields/Categories.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ public function parseField(): mixed
153153

154154
$criteria['status'] = null;
155155
$criteria['limit'] = $limit;
156-
$criteria[$match] = Db::escapeParam($dataValue);
156+
// prep the $dataValue for matching
157+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
157158

158159
Craft::configure($query, $criteria);
159160

src/fields/CommerceProducts.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ public function parseField(): mixed
129129
$criteria['status'] = null;
130130
$criteria['typeId'] = $typeIds;
131131
$criteria['limit'] = $limit;
132-
$criteria[$match] = Db::escapeParam($dataValue);
132+
// prep the $dataValue for matching
133+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
133134

134135
Craft::configure($query, $criteria);
135136

src/fields/CommerceVariants.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
use craft\feedme\base\FieldInterface;
1111
use craft\feedme\helpers\DataHelper;
1212
use craft\feedme\Plugin;
13-
use craft\helpers\Db;
1413
use craft\helpers\Json;
1514

1615
/**
@@ -129,7 +128,8 @@ public function parseField(): mixed
129128
$criteria['status'] = null;
130129
$criteria['typeId'] = $typeIds;
131130
$criteria['limit'] = $limit;
132-
$criteria[$match] = Db::escapeParam($dataValue);
131+
// prep the $dataValue for matching
132+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
133133

134134
Craft::configure($query, $criteria);
135135

src/fields/DigitalProducts.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use craft\feedme\base\FieldInterface;
1010
use craft\feedme\helpers\DataHelper;
1111
use craft\feedme\Plugin;
12-
use craft\helpers\Db;
1312
use craft\helpers\Json;
1413

1514
/**
@@ -130,7 +129,8 @@ public function parseField(): mixed
130129
$criteria['status'] = null;
131130
$criteria['typeId'] = $typeIds;
132131
$criteria['limit'] = $limit;
133-
$criteria[$match] = Db::escapeParam($dataValue);
132+
// prep the $dataValue for matching
133+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
134134

135135
Craft::configure($query, $criteria);
136136

src/fields/Entries.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ public function parseField(): mixed
169169

170170
$criteria['status'] = null;
171171
$criteria['limit'] = $limit;
172-
$criteria[$match] = Db::escapeParam($dataValue);
172+
// prep the $dataValue for matching
173+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
173174

174175
Craft::configure($query, $criteria);
175176

src/fields/Tags.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ public function parseField(): mixed
127127
$criteria['status'] = null;
128128
$criteria['groupId'] = $groupId;
129129
$criteria['limit'] = $limit;
130-
$criteria[$match] = Db::escapeParam($dataValue);
130+
// prep the $dataValue for matching
131+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
131132

132133
Craft::configure($query, $criteria);
133134

src/fields/Users.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ public function parseField(): mixed
155155
$ids = [];
156156
$criteria['status'] = null;
157157
$criteria['limit'] = $limit;
158-
$criteria[$match] = Db::escapeParam($dataValue);
158+
// prep the $dataValue for matching
159+
$criteria[$match] = DataHelper::prepValueForElementMatch($dataValue);
159160

160161
// If the only source for the Users field is "admins" we don't have to bother with this query.
161162
if (!($isAdmin && empty($groupIds) && empty($customSources))) {

src/helpers/DataHelper.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,28 @@ public static function prepDatesForComparison(mixed $firstValue, mixed $secondVa
355355
return [$firstValue, $secondValue];
356356
}
357357

358+
/**
359+
* Prepares given value for finding an element by it.
360+
*
361+
* @param mixed $value
362+
* @return mixed
363+
*/
364+
public static function prepValueForElementMatch(mixed $value): mixed
365+
{
366+
$value = Db::escapeParam($value);
367+
368+
// ensure that if the value is exactly "or" or "and" (case-insensitive), we escape it too
369+
$operators = ['or', 'and'];
370+
foreach ($operators as $operator) {
371+
if (strcasecmp($value, $operator) === 0) {
372+
$value = "=$value";
373+
break;
374+
}
375+
}
376+
377+
return $value;
378+
}
379+
358380
/**
359381
* @param $array1
360382
* @param $array2

0 commit comments

Comments
 (0)