From c2460c4d89ecdf74f48bcd37466dce47d01c4f43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Somhairle=20MacLe=C3=B2id?= Date: Tue, 27 Aug 2024 22:50:59 +0100 Subject: [PATCH] Prevent spaces in names (#5738) * Prevent spaces in names * Create few-icons-refuse.md * fix test --- .changeset/few-icons-refuse.md | 5 +++++ packages/wrangler/src/__tests__/configuration.test.ts | 9 +++++---- packages/wrangler/src/config/validation-helpers.ts | 2 +- 3 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 .changeset/few-icons-refuse.md diff --git a/.changeset/few-icons-refuse.md b/.changeset/few-icons-refuse.md new file mode 100644 index 000000000000..7e08410ed986 --- /dev/null +++ b/.changeset/few-icons-refuse.md @@ -0,0 +1,5 @@ +--- +"wrangler": patch +--- + +fix: Prevent spaces in names when validating diff --git a/packages/wrangler/src/__tests__/configuration.test.ts b/packages/wrangler/src/__tests__/configuration.test.ts index 16e5c81c4ade..cd7bc638fbd6 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -1207,7 +1207,7 @@ describe("normalizeAndValidateConfig()", () => { describe("name", () => { it("should error on invalid `name` value with spaces", () => { const expectedConfig: RawEnvironment = { - name: "NCC 1701 D", + name: "this has spaces", } as unknown as RawEnvironment; const { config, diagnostics } = normalizeAndValidateConfig( @@ -1218,10 +1218,11 @@ describe("normalizeAndValidateConfig()", () => { expect(config).toEqual(expect.objectContaining(expectedConfig)); expect(diagnostics.hasWarnings()).toBe(false); + expect(diagnostics.renderErrors()).toMatchInlineSnapshot(` - "Processing wrangler configuration: - - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"NCC 1701 D\\"." - `); + "Processing wrangler configuration: + - Expected \\"name\\" to be of type string, alphanumeric and lowercase with dashes only but got \\"this has spaces\\"." + `); }); it("should be valid `name` with underscores", () => { diff --git a/packages/wrangler/src/config/validation-helpers.ts b/packages/wrangler/src/config/validation-helpers.ts index d0ec2be44ea1..b7bb8e4248d2 100644 --- a/packages/wrangler/src/config/validation-helpers.ts +++ b/packages/wrangler/src/config/validation-helpers.ts @@ -257,7 +257,7 @@ export const isNonEmptyString: ValidatorFn = ( */ export const isValidName: ValidatorFn = (diagnostics, field, value) => { if ( - (typeof value === "string" && /^$|^[a-z0-9_ ][a-z0-9-_ ]*$/.test(value)) || + (typeof value === "string" && /^$|^[a-z0-9_][a-z0-9-_]*$/.test(value)) || value === undefined ) { return true;