-
Notifications
You must be signed in to change notification settings - Fork 2
Fix stack overflow parsing failure #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
__tests__/VJsonParserTests.res
Outdated
test("long string value", () => { | ||
let longValue = "pzqtdxvnhzvmzzigsojovukwfssmzadolomslufahgjbuininzcexwrkvnncmktcqpdcsrcnerdjrwgcncswsoovrrplikznwfqbvmrkeequwohejmrdmwmfcdkkfwhmqqiqgpfpelmhutdpshonwbtkxmwfoccaqogmzulumtcywyplotpbsldrampwwtmjwsmfhnnzumyhpyforahmivaalkhrenxxvnhuwpovjnkdjbrxvhobpmffinjtuaegkqejfxfejiatxkpxvxboftretjleyxysfwlkiyjfdnvhjdtsopwuvznzpzrzvntiixdqifzsiktwhvgimwpgsgxrbczqhnycsalycgcngilyjwlxkhmaieffcpfptwzqffrlwpksmjbndftkjkjcnwqgbfwoucguujltbcfkerbwrsoeofdmmawmzlegojrujqbkftagqarwbvrlmsgwyxhpcxrdyynjrbltvrtiruhbsmroovmgqfgvogrjshjbhzgucsmavrnyuxqwaqpjhlrqargmuoixwnorvepyvtybqbjrjzyafgzwxedpyezprhtbfzrcmpysfirgemwihpzlmciehdlolhrszfqnserejqqwsazshizvyuuagitooleocilvlfmoriwzpudhqdcngayfyyptuggzloyamzxtrekqeegawxjddprqkrwepeynqifacltgbxsmpqinpaegwkuvbawuuimculerazmttvvqptbyjmnsxrpiwtkqitsoljjqgfsghckooyzdqxeagckeqmmnkpmxqsgvqvbuhlwzgumrslhyvtegfaosnbfgmqdpbkgipiequsjgyopmbiwhvuryzknwayxedhiimqqnddlzgaxbklsvwjigjqltzitphlzguzgljzvylilltqystjnbyafopkanphhuntwbffnslweajomjvgzpkcjznwpnyliymimrfvcdcbcjgwmjdpmlfjiqhizk" | ||
let rawText = ` | ||
{ | ||
"query": "${longValue}", | ||
"variables": { | ||
"searchTerm": "bag", | ||
"sortBy" : {{sortBy}}, | ||
} | ||
}` | ||
expectOkParse(rawText, Object([("variables", Object([("searchTerm", String("bag")), ("sortBy", Variable("sortBy"))]->JsMap.fromArray)),("query", String(longValue))]->JsMap.fromArray)) | ||
}) | ||
}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the added test
src/VJsonParse.res
Outdated
let escapedQuoteRegex = %re(`/\\\\"/gm`) | ||
let inQuotes = %re(`/"(?:[^"\\\\]|\\\\.)*"/gm`) | ||
// Parse a string. Allows for escaped quotes. | ||
// NOTE: not to be confused with `parse`, which takes a raw string and parses | ||
// a whole AST -- this parses string literal syntax. | ||
let parseString: t<string> = | ||
regex(inQuotes) | ||
|> map(match => { | ||
match | ||
->Js.String2.substring(~from=1, ~to_=match->Js.String2.length - 1) // Remove quotes from start and end | ||
->Js.String2.replaceByRe(escapedQuoteRegex, `"`) | ||
}) | ||
|> lexeme |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the updated parser
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Let's get this in there
.res
instead of.re
. I'll add comments to highlight what changed, since most of the diff is file renaming