Skip to content

Commit 8f6dc39

Browse files
committed
Fix regression
While trying to be type correct, coercing the value to string has the unintended side effect of allowing regexes (or any other type) as $regex arg. So instead now throwing an explciit error for that case. Also reverted the type where it returns an Array. Apparently there are cases where it is not an array.
1 parent 4298e55 commit 8f6dc39

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

packages/gatsby/src/redux/run-fast-filters.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function createFilterCacheKey(
8585

8686
function prepareQueryArgs(
8787
filterFields: Array<IInputQuery> | IInputQuery = {}
88-
): Array<IPreparedQueryArg> {
88+
): IPreparedQueryArg {
8989
const filters = {}
9090
Object.keys(filterFields).forEach(key => {
9191
const value = filterFields[key]
@@ -96,7 +96,12 @@ function prepareQueryArgs(
9696
} else {
9797
switch (key) {
9898
case `regex`:
99-
filters[`$regex`] = prepareRegex(String(value))
99+
if (typeof value !== `string`) {
100+
throw new Error(
101+
`The $regex comparator is expecting the regex as a string, not an actual regex or anything else`
102+
)
103+
}
104+
filters[`$regex`] = prepareRegex(value)
100105
break
101106
case `glob`:
102107
filters[`$regex`] = makeRe(value)

0 commit comments

Comments
 (0)