fix(ai): handle escape sequences in INSIDE_OBJECT_KEY state of fixJson#14232
Open
Ricardo-M-L wants to merge 1 commit intovercel:mainfrom
Open
fix(ai): handle escape sequences in INSIDE_OBJECT_KEY state of fixJson#14232Ricardo-M-L wants to merge 1 commit intovercel:mainfrom
Ricardo-M-L wants to merge 1 commit intovercel:mainfrom
Conversation
The INSIDE_OBJECT_KEY state in fixJson did not handle backslash escape sequences, while the INSIDE_STRING state properly handled them by pushing INSIDE_STRING_ESCAPE onto the stack. This inconsistency caused the parser to incorrectly identify the key boundary when an object key contained escape sequences like \", \\, or \n — treating the escaped quote as the end of the key. Add backslash handling to INSIDE_OBJECT_KEY matching the existing INSIDE_STRING behavior, and add test cases for escaped object keys.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
INSIDE_OBJECT_KEYstate infixJsondid not handle backslash escape sequences (\\), while theINSIDE_STRINGstate properly handled them by pushingINSIDE_STRING_ESCAPEonto the stack\",\\, or\n— the escaped quote was treated as the closing delimiter\\case toINSIDE_OBJECT_KEYmatching the existingINSIDE_STRINGbehavior, and added test cases covering escaped object keysBug
For input like
{"key\"name": "value"}, the parser inINSIDE_OBJECT_KEYstate encounters\"and treats the escaped"as the end of the key. It then transitions toINSIDE_OBJECT_AFTER_KEY, expecting a:next — but instead findsname, causing incorrect truncation/parsing.The
INSIDE_STRINGstate (lines 195-214) already handles this correctly:This PR adds the same handling to
INSIDE_OBJECT_KEY.Test plan
\")\\)