Skip to content

Commit

Permalink
Prevent spaces in names (#5738)
Browse files Browse the repository at this point in the history
* Prevent spaces in names

* Create few-icons-refuse.md

* fix test
  • Loading branch information
penalosa committed Aug 27, 2024
1 parent e176ba4 commit c2460c4
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/few-icons-refuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"wrangler": patch
---

fix: Prevent spaces in names when validating
9 changes: 5 additions & 4 deletions packages/wrangler/src/__tests__/configuration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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", () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/wrangler/src/config/validation-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit c2460c4

Please sign in to comment.