Skip to content

Commit

Permalink
make sure every link starts with http:// or https:// / fix s1lvax#14
Browse files Browse the repository at this point in the history
  • Loading branch information
s1lvax committed Oct 12, 2024
1 parent 1f88356 commit 4da83a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/lib/components/LinkForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
method="POST"
use:enhance
action="?/createLink"
class="flex w-full max-w-sm items-center space-x-2"
class="flex w-full max-w-lg items-center justify-start space-x-4"
>
<div class="flex flex-col">
<Form.Field {form} name="title">
Expand All @@ -40,5 +40,5 @@
</Form.Field>
</div>

<Form.Button>Add</Form.Button>
<Form.Button class="mt-5 flex align-bottom">Add</Form.Button>
</form>
8 changes: 7 additions & 1 deletion src/lib/schemas/links.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import { z } from 'zod';

export const linksSchema = z.object({
title: z.string().min(1).max(50),
url: z.string().min(10).max(200)
url: z
.string()
.min(10)
.max(200)
.refine((val) => val.startsWith('http://') || val.startsWith('https://'), {
message: 'Oops! URLs usually start with http:// or https:// :P'
})
});

export type LinksSchema = typeof linksSchema;

0 comments on commit 4da83a2

Please sign in to comment.