Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validation fails for nested fields that contain nonstrings wrapped in quotes #13943

Open
jamescammarano opened this issue Jun 16, 2022 · 1 comment
Labels

Comments

@jamescammarano
Copy link
Contributor

jamescammarano commented Jun 16, 2022

Describe the Bug

Currently the system-filter wraps all values in quotes:
{"_and":[{"_and":[{"id":{"_eq":"5"}}]},{"status":{"_neq":"archived"}}]}

This causes the Joi validation in validatePayload() to fail on these numbers as they are submitted as strings.

A possible solution is to have system-filter use the field type to determine if it should wrap the value in quotes.

To Reproduce

  1. Go to a collection page and enter a filter that contains a number.
  2. See that the filter sends the number wrapped in quotes.

I wrote an automated test to see if validatePayload() could handle the wrong typings:

it('returns an error when the expected field type is a number and it is passed a string', () => {
		const mockFilter = { _and: [{ field: { _eq: '1' } }] } as Filter;
		const mockPayload = { field: 1 };
		
		expect(validatePayload(mockFilter, mockPayload)).toHaveLength(1);
		expect(validatePayload(mockFilter, mockPayload)[0]).toBeInstanceOf(Joi.ValidationError);
		expect(validatePayload(mockFilter, mockPayload)[0]?.message).toBe('"field" must be [1]');
	});

The error is logged.

Errors Shown

From Jest test: [ValidationError: "field" must be [1]]

What version of Directus are you using?

Latest

What version of Node.js are you using?

16.15.0

What database are you using?

Postgres

What browser are you using?

Brave

How are you deploying Directus?

Running locally

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: 📋 Backlog
Development

No branches or pull requests

3 participants