From b4d91769ccf0107a3240fe803a772884d98aa6c0 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 5 Jul 2021 15:14:45 +0100 Subject: [PATCH 1/2] Fixing issue with single quotes in strings breaking JSON parsing. --- packages/server/src/integrations/utils.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 968d9da58e..36880ab913 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -25,6 +25,8 @@ export function generateRowIdField(keyProps: any[] = []) { keyProps = [keyProps] } // this conserves order and types + // we have to swap the double quotes to single quotes for use in HBS statements + // when using the literal helper the double quotes can break things return encodeURIComponent(JSON.stringify(keyProps).replace(/"/g, "'")) } @@ -33,7 +35,11 @@ export function breakRowIdField(_id: string) { if (!_id) { return null } - return JSON.parse(decodeURIComponent(_id)) + // have to replace on the way back as we swapped out the double quotes + // when encoding, but JSON can't handle the single quotes + const decoded = decodeURIComponent(_id).replace(/'/g, "\"") + const parsed = JSON.parse(decoded) + return Array.isArray(parsed) ? parsed : [parsed] } export function convertType(type: string, map: { [key: string]: any }) { From abc19bc2c1c5f90ac10bcefd2b6fc4286d49db09 Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Mon, 5 Jul 2021 15:16:32 +0100 Subject: [PATCH 2/2] Linting. --- packages/server/src/integrations/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/server/src/integrations/utils.ts b/packages/server/src/integrations/utils.ts index 36880ab913..87ed185ba3 100644 --- a/packages/server/src/integrations/utils.ts +++ b/packages/server/src/integrations/utils.ts @@ -37,7 +37,7 @@ export function breakRowIdField(_id: string) { } // have to replace on the way back as we swapped out the double quotes // when encoding, but JSON can't handle the single quotes - const decoded = decodeURIComponent(_id).replace(/'/g, "\"") + const decoded = decodeURIComponent(_id).replace(/'/g, '"') const parsed = JSON.parse(decoded) return Array.isArray(parsed) ? parsed : [parsed] }