Skip to content

Commit

Permalink
trim project name of the user input (#8427)
Browse files Browse the repository at this point in the history
* fix: remove duplicate import

* project name should be trimed

* update changeset
  • Loading branch information
aswind7 authored Sep 6, 2023
1 parent 2272f8d commit b81ff8f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/eighty-gifts-speak.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'create-astro': patch
---

trim project name of the user input
2 changes: 1 addition & 1 deletion packages/create-astro/src/actions/project-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export async function projectName(ctx: Pick<Context, 'cwd' | 'prompt' | 'project
},
});

ctx.cwd = name!;
ctx.cwd = name!.trim();
ctx.projectName = toValidName(name!);
} else {
let name = ctx.cwd;
Expand Down
9 changes: 9 additions & 0 deletions packages/create-astro/test/project-name.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ describe('project name', () => {
expect(context.projectName).to.eq('foobar');
});


it('blank space', async () => {
const context = { projectName: '', cwd: '', prompt: () => ({ name: 'foobar ' }) };
await projectName(context);

expect(context.cwd).to.eq('foobar');
expect(context.projectName).to.eq('foobar');
});

it('normalize', async () => {
const context = { projectName: '', cwd: '', prompt: () => ({ name: 'Invalid Name' }) };
await projectName(context);
Expand Down

0 comments on commit b81ff8f

Please sign in to comment.