Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix: cron parsing (#44795)

Vaibhavc7bd576ca061
diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts
index ecdff361e1d..be744e53280 100644
--- a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts
+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.test.ts
@@ -238,6 +238,19 @@ describe('parseCronJobCommand', () => {
})
})
+ it('should parse a POST body without swallowing later quoted arguments', () => {
+ const command = `select net.http_post( url:='https://example.com/api/endpoint', body:='{"payload":"ok"}'::jsonb, headers:='{"Authorization":"Bearer demo"}'::jsonb, timeout_milliseconds:=5000 );`
+ expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({
+ endpoint: 'https://example.com/api/endpoint',
+ method: 'POST',
+ httpHeaders: [{ name: 'Authorization', value: 'Bearer demo' }],
+ httpBody: '{"payload":"ok"}',
+ timeoutMs: 5000,
+ type: 'http_request',
+ snippet: command,
+ })
+ })
+
it('should return SQL snippet type if the command is an HTTP request that cannot be parsed properly due to positional notation', () => {
const command = `SELECT net.http_post( 'https://webhook.site/dacc2028-a588-462c-9597-c8968e61d0fa', '{"message":"Hello from Supabase"}'::jsonb, '{}'::jsonb, '{"Content-Type":"application/json"}'::jsonb );`
expect(parseCronJobCommand(command, 'random_project_ref')).toStrictEqual({
diff --git a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.tsx b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.tsx
index b730fe724c5..08c43117555 100644
--- a/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.tsx
+++ b/apps/studio/components/interfaces/Integrations/CronJobs/CronJobs.utils.tsx
@@ -54,7 +54,7 @@ export const parseCronJobCommand = (originalCommand: string, projectRef: string)
const urlMatch = command.match(/url:='([^']+)'/i)
const url = urlMatch?.[1] || ''
- const bodyMatch = command.match(/body:='(.*)'/i)
+ const bodyMatch = command.match(/body:='(.*?)'/i)
const body = bodyMatch?.[1] || ''
const timeoutMatch = command.match(/timeout_milliseconds:=(\d+)/i)