From 9330c2040dc2998589be9c606b845703dbf7e2a5 Mon Sep 17 00:00:00 2001 From: Aditya kumar singh <143548997+Adityakk9031@users.noreply.github.com> Date: Mon, 16 Feb 2026 12:47:03 +0530 Subject: [PATCH 1/2] JSON Parser Bug Fix --- .../components/JsonParserReproduction.cy.tsx | 20 +++++++++++++++++++ lib/getPartsOfJson.ts | 8 ++++---- 2 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 cypress/components/JsonParserReproduction.cy.tsx diff --git a/cypress/components/JsonParserReproduction.cy.tsx b/cypress/components/JsonParserReproduction.cy.tsx new file mode 100644 index 000000000..a3201883a --- /dev/null +++ b/cypress/components/JsonParserReproduction.cy.tsx @@ -0,0 +1,20 @@ + +import getPartsOfJson from '../../lib/getPartsOfJson'; + +describe('JsonParserReproduction', () => { + it('should correctly parse JSON with escaped backslash at the end of a string', () => { + const problemJson = `{ "bad_string": "backslash: \\\\", "next_key": "this should be found" }`; + + const parts = getPartsOfJson(problemJson); + + // Check if 'next_key' is identified as an object property + const nextKeyPart = parts.find(p => p.match === 'next_key' && p.type === 'objectProperty'); + + // Log parts for debugging if it fails + if (!nextKeyPart) { + console.log('Parsed parts:', JSON.stringify(parts, null, 2)); + } + + expect(nextKeyPart).to.not.be.undefined; + }); +}); diff --git a/lib/getPartsOfJson.ts b/lib/getPartsOfJson.ts index d8b741ccb..e8310c256 100644 --- a/lib/getPartsOfJson.ts +++ b/lib/getPartsOfJson.ts @@ -6,10 +6,10 @@ const regexObject = const regexArray = /^\s*(?\[)(?.*)(?\])\s*$/g; const regexNumber = /^\s*(?-?\d+(\.\d+)?([Ee][+-]?\d+)?)\s*$/g; -const regexString = /^\s*(?"(\\"|[^"])*")\s*$/g; +const regexString = /^\s*(?"(?:[^"\\]|\\.)*")\s*$/g; const regexBoolean = /^\s*(?true|false)\s*$/g; const regexNull = /^\s*(?null)\s*$/g; -const regexDoubleQuote = /(? Date: Mon, 16 Feb 2026 13:01:29 +0530 Subject: [PATCH 2/2] fix --- .../components/JsonParserReproduction.cy.tsx | 26 ++++++++++--------- lib/getPartsOfJson.ts | 4 +-- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/cypress/components/JsonParserReproduction.cy.tsx b/cypress/components/JsonParserReproduction.cy.tsx index a3201883a..c7dafb1d5 100644 --- a/cypress/components/JsonParserReproduction.cy.tsx +++ b/cypress/components/JsonParserReproduction.cy.tsx @@ -1,20 +1,22 @@ - import getPartsOfJson from '../../lib/getPartsOfJson'; describe('JsonParserReproduction', () => { - it('should correctly parse JSON with escaped backslash at the end of a string', () => { - const problemJson = `{ "bad_string": "backslash: \\\\", "next_key": "this should be found" }`; + it('should correctly parse JSON with escaped backslash at the end of a string', () => { + const problemJson = + '{ "bad_string": "backslash: \\\\", "next_key": "this should be found" }'; - const parts = getPartsOfJson(problemJson); + const parts = getPartsOfJson(problemJson); - // Check if 'next_key' is identified as an object property - const nextKeyPart = parts.find(p => p.match === 'next_key' && p.type === 'objectProperty'); + // Check if 'next_key' is identified as an object property + const nextKeyPart = parts.find( + (p) => p.match === 'next_key' && p.type === 'objectProperty', + ); - // Log parts for debugging if it fails - if (!nextKeyPart) { - console.log('Parsed parts:', JSON.stringify(parts, null, 2)); - } + // Log parts for debugging if it fails + if (!nextKeyPart) { + console.log('Parsed parts:', JSON.stringify(parts, null, 2)); + } - expect(nextKeyPart).to.not.be.undefined; - }); + expect(nextKeyPart).to.not.be.undefined; + }); }); diff --git a/lib/getPartsOfJson.ts b/lib/getPartsOfJson.ts index e8310c256..6d9ef7991 100644 --- a/lib/getPartsOfJson.ts +++ b/lib/getPartsOfJson.ts @@ -284,8 +284,8 @@ const getPartsOfJsonObjectContent = ( stringWithPayload.index + (hasComma ? indexOfComma + - stringWithPayload.match.length - - stringWithPayload.payload.length + stringWithPayload.match.length - + stringWithPayload.payload.length : stringWithPayload.match.length); const payload = serializedJson.substr( payloadStartIndex,