diff --git a/desktop/plugins/databases/UpdateQueryUtil.tsx b/desktop/plugins/databases/UpdateQueryUtil.tsx index f2290c45c..59823b16e 100644 --- a/desktop/plugins/databases/UpdateQueryUtil.tsx +++ b/desktop/plugins/databases/UpdateQueryUtil.tsx @@ -51,13 +51,12 @@ export function constructQueryClause( ): string { return Object.entries(values).reduce( (clauses, [key, val]: [string, Value], idx) => { - const {type, value} = val; const valueString = - type === 'null' + val.type === 'null' ? 'NULL' - : type === 'string' || type === 'blob' - ? `'${value}'` - : `${value}`; + : val.type === 'string' || val.type === 'blob' + ? `'${val.value.replace(/'/g, "''")}'` + : `${val.value}`; if (idx <= 0) { return `${key}=${valueString}`; } else { diff --git a/desktop/plugins/databases/__test__/UpdateQueryUtil.node.tsx b/desktop/plugins/databases/__test__/UpdateQueryUtil.node.tsx index d5877f3c3..fb8844485 100644 --- a/desktop/plugins/databases/__test__/UpdateQueryUtil.node.tsx +++ b/desktop/plugins/databases/__test__/UpdateQueryUtil.node.tsx @@ -248,6 +248,15 @@ test('constructQueryClause with exactly one null value', () => { ).toEqual(`key1=NULL`); }); +test("constructQueryClause with special character (single quote ('))", () => { + expect( + constructQueryClause( + {key1: {type: 'string', value: "this is a 'single quote'"}}, + 'connecter', + ), + ).toEqual(`key1='this is a ''single quote'''`); +}); + test('constructQueryClause with multiple value', () => { const values: {[key: string]: Value} = { key1: {type: 'string', value: 'this is a string'}, @@ -260,6 +269,19 @@ test('constructQueryClause with multiple value', () => { ); }); +test('constructQueryClause with multiple value with single quotes mixed in string', () => { + const values: {[key: string]: Value} = { + key1: {type: 'string', value: `this is 'a' string`}, + key2: {type: 'null', value: null}, + key3: {type: 'float', value: 13.37}, + key4: {type: 'string', value: `there are single quotes 'here' and 'there'`}, + }; + + expect(constructQueryClause(values, 'connector')).toEqual( + `key1='this is ''a'' string' connector key2=NULL connector key3=13.37 connector key4='there are single quotes ''here'' and ''there'''`, + ); +}); + test('constructUpdateQuery', () => { const setClause: {[key: string]: Value} = { key1: {type: 'string', value: 'this is a string'},