From 38088e9cbff4d0e372205b661fc69577bf5ce337 Mon Sep 17 00:00:00 2001 From: Michael Becke Date: Mon, 15 Sep 2025 16:40:03 -0700 Subject: [PATCH 1/3] Add tests. --- api/test/api.test.ts | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/api/test/api.test.ts b/api/test/api.test.ts index 69391a96..82723dd4 100644 --- a/api/test/api.test.ts +++ b/api/test/api.test.ts @@ -105,6 +105,8 @@ import { intervalValue, listValue, mapValue, + quotedIdentifier, + quotedString, structValue, timeTZValue, timeValue, @@ -2402,4 +2404,45 @@ ORDER BY name }); }); }); + + describe('SQL utility functions', () => { + test('quotedString', async () => { + // Basic string + assert.equal(quotedString('hello'), "'hello'"); + + // String with single quotes + assert.equal(quotedString("it's"), "'it''s'"); + assert.equal(quotedString("'quoted'"), "'''quoted'''"); + + // String with multiple single quotes + assert.equal(quotedString("it's 'really' good"), "'it''s ''really'' good'"); + + // Empty string + assert.equal(quotedString(''), "''"); + + // String with special characters + assert.equal(quotedString('hello\nworld'), "'hello\nworld'"); + assert.equal(quotedString('tab\there'), "'tab\there'"); + }); + + test('quotedIdentifier', async () => { + // Basic identifier + assert.equal(quotedIdentifier('table_name'), '"table_name"'); + + // Identifier with double quotes + assert.equal(quotedIdentifier('my"table'), '"my""table"'); + assert.equal(quotedIdentifier('"column"'), '"""column"""'); + + // Identifier with multiple double quotes + assert.equal(quotedIdentifier('my"special"table'), '"my""special""table"'); + + // Empty identifier + assert.equal(quotedIdentifier(''), '""'); + + // Identifier with special characters + assert.equal(quotedIdentifier('table-name'), '"table-name"'); + assert.equal(quotedIdentifier('table.name'), '"table.name"'); + assert.equal(quotedIdentifier('table name'), '"table name"'); + }); + }); }); From 78d646b35917883121c48bfe191c0c350f8ce60a Mon Sep 17 00:00:00 2001 From: Michael Becke Date: Mon, 15 Sep 2025 16:40:09 -0700 Subject: [PATCH 2/3] Fix tests. --- api/src/sql.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/src/sql.ts b/api/src/sql.ts index 91460dab..e603cb33 100644 --- a/api/src/sql.ts +++ b/api/src/sql.ts @@ -1,7 +1,7 @@ export function quotedString(input: string): string { - return `'${input.replace(`'`, `''`)}'`; + return `'${input.replaceAll(`'`, `''`)}'`; } export function quotedIdentifier(input: string): string { - return `"${input.replace(`"`, `""`)}"`; + return `"${input.replaceAll(`"`, `""`)}"`; } From 89af877859b2f8a6be9c2b49c9841e6895f4525a Mon Sep 17 00:00:00 2001 From: Michael Becke Date: Mon, 15 Sep 2025 16:47:50 -0700 Subject: [PATCH 3/3] Remove async. --- api/test/api.test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/test/api.test.ts b/api/test/api.test.ts index 82723dd4..017e80c4 100644 --- a/api/test/api.test.ts +++ b/api/test/api.test.ts @@ -2406,7 +2406,7 @@ ORDER BY name }); describe('SQL utility functions', () => { - test('quotedString', async () => { + test('quotedString', () => { // Basic string assert.equal(quotedString('hello'), "'hello'"); @@ -2425,7 +2425,7 @@ ORDER BY name assert.equal(quotedString('tab\there'), "'tab\there'"); }); - test('quotedIdentifier', async () => { + test('quotedIdentifier', () => { // Basic identifier assert.equal(quotedIdentifier('table_name'), '"table_name"');