Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cypress/components/JsonParserReproduction.cy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +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" }';

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;
});
});
4 changes: 2 additions & 2 deletions lib/getPartsOfJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ const regexObject =
const regexArray =
/^\s*(?<arrayStartBracket>\[)(?<arrayContent>.*)(?<arrayEndBracket>\])\s*$/g;
const regexNumber = /^\s*(?<number>-?\d+(\.\d+)?([Ee][+-]?\d+)?)\s*$/g;
const regexString = /^\s*(?<string>"(\\"|[^"])*")\s*$/g;
const regexString = /^\s*(?<string>"(?:[^"\\]|\\.)*")\s*$/g;
const regexBoolean = /^\s*(?<boolean>true|false)\s*$/g;
const regexNull = /^\s*(?<null>null)\s*$/g;
const regexDoubleQuote = /(?<!\\)"/g;
const regexDoubleQuote = /(?<=(?:^|[^\\])(?:\\\\)*)"/g;
const regexCommaOrEndOfLine = /,/g;

export type SyntaxPart = {
Expand Down
Loading