trim project name of the user input (#8427)

* fix: remove duplicate import

* project name should be trimed

* update changeset
This commit is contained in:
aswind7 2023-09-06 21:22:18 +08:00 committed by GitHub
parent 2272f8d3c4
commit b81ff8fcef
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View file

@ -0,0 +1,5 @@
---
'create-astro': patch
---
trim project name of the user input

View file

@ -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!); ctx.projectName = toValidName(name!);
} else { } else {
let name = ctx.cwd; let name = ctx.cwd;

View file

@ -62,6 +62,15 @@ describe('project name', () => {
expect(context.projectName).to.eq('foobar'); 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 () => { it('normalize', async () => {
const context = { projectName: '', cwd: '', prompt: () => ({ name: 'Invalid Name' }) }; const context = { projectName: '', cwd: '', prompt: () => ({ name: 'Invalid Name' }) };
await projectName(context); await projectName(context);