The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: limit regex (#47717)
Vaibhavc070893475be
diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts b/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.tsindex 799b6562075..51b01338b15 100644--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.test.ts@@ -53,12 +53,24 @@ describe('SQLEditor.utils.ts:checkIfAppendLimitRequired', () => {const { appendAutoLimit } = checkIfAppendLimitRequired(sql, limit)expect(appendAutoLimit).toBe(false)})+ test('Should return false if query already has a limit with whitespace before the semi colon', () => {+ const sql = 'select * from countries limit 10 ;'+ const limit = 100+ const { appendAutoLimit } = checkIfAppendLimitRequired(sql, limit)+ expect(appendAutoLimit).toBe(false)+ })test('Should return false if query already has a limit and offset', () => {const sql = 'select * from countries limit 10 offset 0;'const limit = 100const { appendAutoLimit } = checkIfAppendLimitRequired(sql, limit)expect(appendAutoLimit).toBe(false)})+ test('Should return false if query already has a limit and offset with whitespace before the semi colon', () => {+ const sql = 'select * from countries limit 10 offset 0 ;'+ const limit = 100+ const { appendAutoLimit } = checkIfAppendLimitRequired(sql, limit)+ expect(appendAutoLimit).toBe(false)+ })test('Should return false if query already has a limit and offset (flip order of limit and offset)', () => {const sql = 'select * from countries offset 0 limit 1;'const limit = 100@@ -154,6 +166,12 @@ describe('SQLEditor.utils.ts:suffixWithLimit', () => {const formattedSql = suffixWithLimit(sql, limit)expect(formattedSql).toBe('select * from countries limit 100;')})+ test('Should not append a limit if query already has one with whitespace before the semi colon', () => {+ const sql = safeSql`select * from countries limit 10 ;`+ const limit = 100+ const formattedSql = suffixWithLimit(sql, limit)+ expect(formattedSql).toBe('select * from countries limit 10 ;')+ })})describe(`SQLEditor.utils.ts:checkDestructiveQuery`, () => {diff --git a/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts b/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.tsindex 9e01e8c24a2..d662302048d 100644--- a/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts+++ b/apps/studio/components/interfaces/SQLEditor/SQLEditor.utils.ts@@ -249,8 +249,8 @@ export const checkIfAppendLimitRequired = (sql: string, limit: number = 0) => {!cleanedSql.toLowerCase().match(/fetch\s+first/i) &&!cleanedSql.match(/limit$/i) &&!cleanedSql.match(/limit;$/i) &&- !cleanedSql.match(/limit [0-9]* offset [0-9]*[;]?$/i) &&- !cleanedSql.match(/limit [0-9]*[;]?$/i)+ !cleanedSql.match(/limit [0-9]* offset [0-9]*\s*[;]?$/i) &&+ !cleanedSql.match(/limit [0-9]*\s*[;]?$/i)return { cleanedSql, appendAutoLimit }}