From fff1abbba760c51f698947ae70aef6837acded5e Mon Sep 17 00:00:00 2001
From: jacobshandling <61553566+jacobshandling@users.noreply.github.com>
Date: Thu, 11 Dec 2025 16:50:51 -0800
Subject: [PATCH] Trim whitespace before validating queries (#37157)
**Related issue:** Resolves
https://github.com/fleetdm/fleet/issues/35058#issuecomment-3638500906
- [x] Added/updated automated tests
- [x] QA'd all new/changed functionality manually
---
.../forms/validators/validate_query/index.ts | 2 +-
.../validators/validate_query/validate_query.tests.ts | 10 ++++++----
2 files changed, 7 insertions(+), 5 deletions(-)
diff --git a/frontend/components/forms/validators/validate_query/index.ts b/frontend/components/forms/validators/validate_query/index.ts
index 64e47f264c..3e1228571a 100644
--- a/frontend/components/forms/validators/validate_query/index.ts
+++ b/frontend/components/forms/validators/validate_query/index.ts
@@ -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);
}
diff --git a/frontend/components/forms/validators/validate_query/validate_query.tests.ts b/frontend/components/forms/validators/validate_query/validate_query.tests.ts
index 13324f5a38..46fedab69b 100644
--- a/frontend/components/forms/validators/validate_query/validate_query.tests.ts
+++ b/frontend/components/forms/validators/validate_query/validate_query.tests.ts
@@ -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", () => {