diff --git a/lib/getPartsOfJson.ts b/lib/getPartsOfJson.ts index d8b741ccb..138a49be7 100644 --- a/lib/getPartsOfJson.ts +++ b/lib/getPartsOfJson.ts @@ -9,9 +9,21 @@ const regexNumber = /^\s*(?-?\d+(\.\d+)?([Ee][+-]?\d+)?)\s*$/g; const regexString = /^\s*(?"(\\"|[^"])*")\s*$/g; const regexBoolean = /^\s*(?true|false)\s*$/g; const regexNull = /^\s*(?null)\s*$/g; -const regexDoubleQuote = /(? { + 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; @@ -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) => {