From f5f1efcaf70b0fc28f463c48974453ab63cd49ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Tue, 29 Aug 2023 10:41:09 +0200 Subject: [PATCH 1/2] Fix parse json context webclient#569 --- src/helpers/contextParser.ts | 2 +- src/spec/contextParser.spec.ts | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/helpers/contextParser.ts b/src/helpers/contextParser.ts index 22e81b1..4a82f61 100644 --- a/src/helpers/contextParser.ts +++ b/src/helpers/contextParser.ts @@ -81,7 +81,7 @@ export const parseContext = ({ function tryParseJSON(str: string): any | null { try { - const parsedJSON = JSON.parse(str); + const parsedJSON = JSON.parse(str.replace(/'/g, '"')); return parsedJSON; } catch (error) { return null; diff --git a/src/spec/contextParser.spec.ts b/src/spec/contextParser.spec.ts index d3afdec..2c5f346 100644 --- a/src/spec/contextParser.spec.ts +++ b/src/spec/contextParser.spec.ts @@ -129,4 +129,10 @@ describe("A Context Parser", () => { expect(parsedContext!["person"].name).toBe("John Doe"); expect(JSON.stringify(parsedContext)).toBe(JSON.stringify(ctx)); }); + + it.only("should parse context with simple single quotes in a string", () => { + const string = "{'contract_id': 1, 'contract_ids': [1, 3]}"; + const parsedContext = parseContext({ context: string }); + expect(parsedContext!["contract_id"]).toBe(1); + }); }); From 8d55257c446dea1925d3333f2fb3b8cb6e1ebcd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Gu=CC=88ell=20Segarra?= Date: Mon, 4 Sep 2023 10:33:00 +0200 Subject: [PATCH 2/2] Bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2ec9cdc..d3b42f8 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@gisce/ooui", - "version": "0.22.0", + "version": "0.22.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@gisce/ooui", - "version": "0.22.0", + "version": "0.22.1", "dependencies": { "html-entities": "^2.3.3", "moment": "^2.29.3" diff --git a/package.json b/package.json index 542c8f1..334ac93 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@gisce/ooui", - "version": "0.22.0", + "version": "0.22.1", "main": "./dist/ooui.umd.js", "module": "./dist/ooui.es.js", "types": "./dist/index.d.ts",