Skip to content

Commit 80fcda9

Browse files
committed
improve regex + more tests
1 parent e9b388b commit 80fcda9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/lib/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,12 @@ export function validateSupabaseUrl(supabaseUrl: string): URL {
8686
throw new Error('supabaseUrl is required.')
8787
}
8888

89-
if (!supabaseUrl.match(/^https?:\/\/.+/i)) {
89+
if (!trimmedUrl.match(/^https?:\/\//i)) {
9090
throw new Error('Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL.')
9191
}
9292

9393
try {
94-
return new URL(ensureTrailingSlash(supabaseUrl))
94+
return new URL(ensureTrailingSlash(trimmedUrl))
9595
} catch {
9696
throw Error('Invalid supabaseUrl: Provided URL is malformed.')
9797
}

test/unit/SupabaseClient.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ describe('SupabaseClient', () => {
4141
expect(() => createClient('http:/localhost:3000', KEY)).toThrow(
4242
'Invalid supabaseUrl: Must be a valid HTTP or HTTPS URL.'
4343
)
44+
45+
expect(() => createClient(' https://xyz123.supabase.co ', KEY)).not.toThrow()
46+
expect(() => createClient('http://user:pass@localhost:54321', KEY)).not.toThrow()
4447
})
4548

4649
describe('URL Construction', () => {

0 commit comments

Comments
 (0)