Skip to content

Commit 0710a97

Browse files
rexxarsclaude
andcommitted
fix(deploy): reject hostnames with trailing hyphens
Tighten the hostname regex to disallow trailing hyphens, which are invalid per DNS rules and would fail at the API with a confusing error. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 407de2a commit 0710a97

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/@sanity/cli/src/actions/deploy/deployStudio.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ function resolveAppHost({
237237
}
238238

239239
// Validate hostname characters (alphanumeric and hyphens only)
240-
if (!/^[a-z0-9][a-z0-9-]*$/i.test(hostname)) {
240+
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/i.test(hostname)) {
241241
output.error(
242242
`Invalid studio hostname "${hostname}". Hostnames can only contain letters, numbers, and hyphens.`,
243243
{exit: 1},

packages/@sanity/cli/src/commands/__tests__/deploy.studio.test.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,6 +1525,25 @@ describe('#deploy studio', () => {
15251525
expect(error?.message).toContain('Invalid studio hostname')
15261526
expect(error?.message).toContain('letters, numbers, and hyphens')
15271527
})
1528+
1529+
test('should reject --url with trailing hyphen', async () => {
1530+
const cwd = await testFixture('basic-studio')
1531+
process.cwd = () => cwd
1532+
1533+
const projectId = 'test-project-id'
1534+
1535+
const {error} = await testCommand(DeployCommand, ['--url', 'my-studio-'], {
1536+
config: {root: cwd},
1537+
mocks: {
1538+
cliConfig: {
1539+
api: {projectId},
1540+
},
1541+
},
1542+
})
1543+
1544+
expect(error).toBeInstanceOf(Error)
1545+
expect(error?.message).toContain('Invalid studio hostname')
1546+
})
15281547
})
15291548

15301549
describe('unattended mode', () => {

0 commit comments

Comments
 (0)