Skip to content
Merged
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
4 changes: 2 additions & 2 deletions src/VJsonParse.res
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ let parseVJsonWithVariable = parseVariableString => {
\"<|>"(str("true") |> map(_ => true), str("false") |> map(_ => false)) |> lexeme

let escapedQuoteRegex = %re(`/\\\\"/gm`)
let nonEsacapedQuoteRegex = %re(`/(?<!\\\\)(?:\\\\{2})*"/gm`)
let nonEscapedQuoteRegex = %re(`/((?:^|[^\\\\])(?:\\\\{2})*)"/gm`)
let inQuotesRegex = %re(`/"(?:[^"\\\\]|\\\\.)*"/`)
// Parse a string. Allows for escaped quotes.
// NOTE: not to be confused with `parse`, which takes a raw string and parses
Expand All @@ -35,7 +35,7 @@ let parseVJsonWithVariable = parseVariableString => {
regex(inQuotesRegex)
|> map(match => {
match
->Js.String2.replaceByRe(nonEsacapedQuoteRegex, ``)
->Js.String2.replaceByRe(nonEscapedQuoteRegex, `$1`) // First group of the regex is characters before the quote that should be kept
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

->Js.String2.replaceByRe(escapedQuoteRegex, `"`)
})
|> lexeme
Expand Down