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 d5750d868343..0f13388adb5e 100644 --- a/packages/wrangler/src/__tests__/configuration.test.ts +++ b/packages/wrangler/src/__tests__/configuration.test.ts @@ -1123,7 +1123,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( @@ -1134,10 +1134,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 845d2d0afced..c0b98418f250 100644 --- a/packages/wrangler/src/config/validation-helpers.ts +++ b/packages/wrangler/src/config/validation-helpers.ts @@ -236,7 +236,7 @@ export const isString: ValidatorFn = (diagnostics, field, value) => { */ 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;