The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix broken regex and write tests
Joshen Lima31f39d8b85c
diff --git a/studio/components/interfaces/Auth/Auth.constants.ts b/studio/components/interfaces/Auth/Auth.constants.tsindex 1cf6d30dcca..9a19233214a 100644--- a/studio/components/interfaces/Auth/Auth.constants.ts+++ b/studio/components/interfaces/Auth/Auth.constants.ts@@ -5,8 +5,10 @@// "www.vercel.com"// "uptime-monitor-fe.vercel.app"// "https://uptime-monitor-fe.vercel.app/"++// Supports wildcards, port numbers at the end, paths at the end and query paramsconst baseDomainRegex =- /^((ftp|http|https):\/\/)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_*-]+(\.[a-zA-Z0-9_*-]+)+((\/)[\w#]+)*(\/\w+\?[a-zA-Z0-9_]+=\w+(&[a-zA-Z0-9_]+=\w+)*)?+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))(.*)?\/?(.)*$/gm+ /^((ftp|http|https):\/\/)?(www.)?(?!.*(ftp|http|https|www.))[a-zA-Z0-9_*-]+(\.[a-zA-Z0-9_*-]+)+((\/)[\w#]+)*(\/\w+\?[a-zA-Z0-9_]+=\w+(&[a-zA-Z0-9_]+=\w+)*)+(?:\.[a-z]+)*(?::\d+)?(?![^<]*(?:<\/\w+>|\/?>))(.*)?\/?(.)*?$/gm// iOS deep linking scheme https://benoitpasquier.com/deep-linking-url-scheme-ios/const appRegex = /^[a-z0-9]+([.][a-z0-9]+)*:\/(\/[-a-z0-9._~!$&'()*+,;=:@%]+)+$/idiff --git a/studio/tests/components/Auth/Auth.constants.test.js b/studio/tests/components/Auth/Auth.constants.test.jsnew file mode 100644index 00000000000..e10824d0d1e--- /dev/null+++ b/studio/tests/components/Auth/Auth.constants.test.js@@ -0,0 +1,66 @@+import { domainRegex } from 'components/interfaces/Auth/Auth.constants'++describe('Auth.constants: domainRegex', () => {+ test('should validate typical URLs', () => {+ const mockInput1 = 'http://domain.com'+ const output1 = domainRegex.test(mockInput1)+ expect(output1).toBe(true)++ const mockInput2 = 'https://supabase.io'+ const output2 = domainRegex.test(mockInput2)+ expect(output2).toBe(true)++ const mockInput3 = 'https://new-domain-vercel.com'+ const output3 = domainRegex.test(mockInput3)+ expect(output3).toBe(true)++ const mockInput4 = 'www.test-domain.com'+ const output4 = domainRegex.test(mockInput4)+ expect(output4).toBe(true)+ })+ test('should validate subdomains', () => {+ const mockInput1 = 'https://app.supabase.com'+ const output1 = domainRegex.test(mockInput1)+ expect(output1).toBe(true)+ })+ test('should validate localhost URLs', () => {+ const mockInput1 = 'http://localhost:3000'+ const output1 = domainRegex.test(mockInput1)+ expect(output1).toBe(true)+ })+ test('should validate URLs with query params', () => {+ const mockInput1 = 'https://supabase.com?name=test'+ const output1 = domainRegex.test(mockInput1)+ expect(output1).toBe(true)++ const mockInput2 = 'https://supabase.com?name=test&description=hello&page=2'+ const output2 = domainRegex.test(mockInput2)+ expect(output2).toBe(true)+ })+ test('should validate URLs with wildcards', () => {+ const mockInput1 = 'https://supabase*.com'+ const output1 = domainRegex.test(mockInput1)+ expect(output1).toBe(true)++ const mockInput2 = 'https://supabase.com/*'+ const output2 = domainRegex.test(mockInput2)+ expect(output2).toBe(true)+ })+ test('should invalidate invalid URLs', () => {+ const mockInput1 = 'supabase'+ const output1 = domainRegex.test(mockInput1)+ expect(output1).toBe(false)++ const mockInput2 = 'mailto:[email protected]'+ const output2 = domainRegex.test(mockInput2)+ expect(output2).toBe(false)++ const mockInput4 = 'hello world.com'+ const output4 = domainRegex.test(mockInput4)+ expect(output4).toBe(false)++ const mockInput5 = '[email protected]'+ const output5 = domainRegex.test(mockInput5)+ expect(output5).toBe(false)+ })+})