Skip to content
Open
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
29 changes: 24 additions & 5 deletions lib/getPartsOfJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@ const regexNumber = /^\s*(?<number>-?\d+(\.\d+)?([Ee][+-]?\d+)?)\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;

const isEscapedQuote = (str: string, quoteIndex: number) => {
let backslashCount = 0;
let i = quoteIndex - 1;

while (i >= 0 && str[i] === '\\') {
backslashCount++;
i--;
}

return backslashCount % 2 === 1;
};

export type SyntaxPart = {
type: string;
address?: string;
Expand Down Expand Up @@ -188,10 +200,17 @@ const getPartsOfJsonObjectContent = (
offset = 0,
jsonPath: string,
): SyntaxPart[] => {
const doubleQuoteMatches = getFindResultsByGlobalRegExp(
serializedJson,
regexDoubleQuote,
);
const doubleQuoteMatches: RegExpResult[] = [];

for (let i = 0; i < serializedJson.length; i++) {
if (serializedJson[i] === '"' && !isEscapedQuote(serializedJson, i)) {
doubleQuoteMatches.push({
index: i,
match: '"',
groups: [],
});
}
}
let keywordStartIndex = 0;
let stringsWithPayload: StringWithPayload[] = [];
doubleQuoteMatches.forEach((doubleQuoteMatch, index) => {
Expand Down
Loading