fix: handle escaped single quotes when formatting multiline strings - #454
Open
Sanjays2402 wants to merge 1 commit into
Open
fix: handle escaped single quotes when formatting multiline strings#454Sanjays2402 wants to merge 1 commit into
Sanjays2402 wants to merge 1 commit into
Conversation
format_multiline_strings used the regex `('.*?'\s*){2,}` to find
concatenated single-quoted string literals, and `'.*'` to extract them.
Neither accounts for a backslash-escaped quote, so a GraphQL operation
containing `'` (e.g. a ShopifyQL `WHERE type = 'Product'` argument) had
its literal truncated at the escaped quote. convert_to_multiline_string
then stripped quotes blindly, emitting a broken triple-quoted string and
codegen aborted with black.parsing.InvalidInput.
Both patterns now use a shared SINGLE_QUOTED_STRING regex that skips
escaped characters, and convert_to_multiline_string decodes the literal
with ast.literal_eval (falling back to the old behavior for input that
is not a valid literal).
Closes mirumee#423
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Closes #423
format_multiline_stringsmatched concatenated single-quoted literals with('.*?'\s*){2,}and extracted them with'.*', neither of which accounts for a backslash-escaped quote. A GraphQL operation containing'(such as a ShopifyQLWHERE landing_page_type = 'Product'argument) had its literal truncated at the escaped quote, soconvert_to_multiline_stringemitted a malformed triple-quoted string and codegen aborted withblack.parsing.InvalidInput.Both patterns now share a
SINGLE_QUOTED_STRINGregex that skips escaped characters, andconvert_to_multiline_stringdecodes the literal viaast.literal_evalinstead of stripping every'(falling back to the previous behavior for input that is not a valid literal). New test intests/test_utils.pyfails without the fix and passes with it.