mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fix string filter unexpectedly being casted to number (#10138)
* Fix string unexpectedly being casted to numbers * Parse filter with multiple keys into `_and` block. * Fixed filter structure in tests
This commit is contained in:
@@ -7,7 +7,7 @@ import { RequestHandler } from 'express';
|
||||
import { sanitizeQuery } from '../utils/sanitize-query';
|
||||
import { validateQuery } from '../utils/validate-query';
|
||||
|
||||
const sanitizeQueryMiddleware: RequestHandler = (req, res, next) => {
|
||||
const sanitizeQueryMiddleware: RequestHandler = (req, _res, next) => {
|
||||
req.sanitizedQuery = {};
|
||||
if (!req.query) return;
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import logger from '../logger';
|
||||
import { Meta } from '../types';
|
||||
import { Query, Aggregate, Filter } from '@directus/shared/types';
|
||||
import { Accountability } from '@directus/shared/types';
|
||||
import { parseFilter, deepMap } from '@directus/shared/utils';
|
||||
import { parseFilter } from '@directus/shared/utils';
|
||||
|
||||
export function sanitizeQuery(rawQuery: Record<string, any>, accountability?: Accountability | null): Query {
|
||||
const query: Query = {};
|
||||
@@ -124,18 +124,6 @@ function sanitizeFilter(rawFilter: any, accountability: Accountability | null) {
|
||||
}
|
||||
}
|
||||
|
||||
filters = deepMap(filters, (val) => {
|
||||
try {
|
||||
const parsed = JSON.parse(val);
|
||||
|
||||
if (typeof parsed == 'number' && !Number.isSafeInteger(parsed)) return val;
|
||||
|
||||
return parsed;
|
||||
} catch {
|
||||
return val;
|
||||
}
|
||||
});
|
||||
|
||||
return parseFilter(filters, accountability);
|
||||
}
|
||||
|
||||
|
||||
@@ -103,7 +103,7 @@ function validateFilterPrimitive(value: any, key: string) {
|
||||
throw new InvalidQueryException(`The filter value for "${key}" has to be a string, number, or boolean`);
|
||||
}
|
||||
|
||||
if (typeof value === 'number' && Number.isNaN(value)) {
|
||||
if (typeof value === 'number' && (Number.isNaN(value) || !Number.isSafeInteger(value))) {
|
||||
throw new InvalidQueryException(`The filter value for "${key}" is not a valid number`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user