Trim whitespace before validating queries (#37157)
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves https://github.com/fleetdm/fleet/issues/35058#issuecomment-3638500906 <img width="719" height="350" alt="image" src="https://github.com/user-attachments/assets/37670ab6-3d3d-412d-972f-59f0e70c2fc4" /> <img width="413" height="340" alt="image" src="https://github.com/user-attachments/assets/66184f15-bbca-472a-8f7d-26f16e4e5519" /> <img width="843" height="952" alt="image" src="https://github.com/user-attachments/assets/47949b63-68fd-4359-9948-ea9bed8cd5f6" /> <img width="807" height="993" alt="image" src="https://github.com/user-attachments/assets/167599a8-b2d9-44b3-a197-f217a69c625c" /> - [x] Added/updated automated tests - [x] QA'd all new/changed functionality manually
This commit is contained in:
@@ -11,7 +11,7 @@ const validQueryResponse = { valid: true, error: null };
|
||||
const parser = new Parser();
|
||||
|
||||
export const validateQuery = (queryText?: string) => {
|
||||
if (!queryText) {
|
||||
if (!queryText?.trim()) {
|
||||
return invalidQueryResponse(EMPTY_QUERY_ERR);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,10 +27,12 @@ describe("validateQuery", () => {
|
||||
});
|
||||
|
||||
it("rejects blank queries", () => {
|
||||
const { error, valid } = validateQuery();
|
||||
|
||||
expect(valid).toEqual(false);
|
||||
expect(error).toEqual(EMPTY_QUERY_ERR);
|
||||
const cases = [undefined, "", " ", " ", "\t", "\n"];
|
||||
cases.forEach((query) => {
|
||||
const { error, valid } = validateQuery(query);
|
||||
expect(valid).toEqual(false);
|
||||
expect(error).toEqual(EMPTY_QUERY_ERR);
|
||||
});
|
||||
});
|
||||
|
||||
it("accepts valid queries", () => {
|
||||
|
||||
Reference in New Issue
Block a user