Skip to content

Commit 8b4b3eb

Browse files
authored
fix[lib]:Update to filter brackets ({, }, [, ]) that appear inside strings (#1268)
1 parent 27c63e5 commit 8b4b3eb

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

lib/getPartsOfJson.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -366,21 +366,30 @@ const getPartsOfArrayContent = (
366366
const length = match.index - arrayPayloadIndex;
367367
const payload = serializedJson.substr(arrayPayloadIndex, length);
368368

369-
//ToDo filter brackets in strings
369+
const stringMatches = getFindResultsByGlobalRegExp(payload, regexString);
370+
let filteredPayload = payload;
371+
372+
// Replace content of strings with placeholders to avoid counting brackets inside them
373+
stringMatches.forEach((stringMatch) => {
374+
const stringContent = stringMatch.match;
375+
const placeholder = '_'.repeat(stringContent.length);
376+
filteredPayload = filteredPayload.replace(stringContent, placeholder);
377+
});
378+
370379
const countOpenCurlyBracketsInPayload = getFindResultsByGlobalRegExp(
371-
payload,
380+
filteredPayload,
372381
/\{/g,
373382
).length;
374383
const countClosedCurlyBracketsInPayload = getFindResultsByGlobalRegExp(
375-
payload,
384+
filteredPayload,
376385
/\}/g,
377386
).length;
378387
const countOpenSquaredBracketsInPayload = getFindResultsByGlobalRegExp(
379-
payload,
388+
filteredPayload,
380389
/\[/g,
381390
).length;
382391
const countClosedSquaredBracketsInPayload = getFindResultsByGlobalRegExp(
383-
payload,
392+
filteredPayload,
384393
/\]/g,
385394
).length;
386395
const openCurlyBrackets =

0 commit comments

Comments
 (0)