fix: escape file paths in GraphQL expressions to prevent query syntax errors#201
Open
njlazzar-su wants to merge 2 commits intoentrius:testfrom
Open
fix: escape file paths in GraphQL expressions to prevent query syntax errors#201njlazzar-su wants to merge 2 commits intoentrius:testfrom
njlazzar-su wants to merge 2 commits intoentrius:testfrom
Conversation
… syntax errors File paths are interpolated directly into GraphQL query strings via f-strings without escaping. If a filename contains double quotes or backslashes, the resulting GraphQL query will have broken syntax, causing the file content fetch to fail silently (returns None, scoring the file as 0). Escape backslashes and double quotes in file paths before interpolation in both fetch_file_contents_batch() and fetch_file_contents_with_base().
Collaborator
|
needs to target test branch |
Contributor
Author
|
fixed |
Contributor
Author
|
Hi @anderdc what are next steps here? |
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
Escape file paths before interpolating them into GraphQL query strings to prevent syntax errors.
Problem
In both
fetch_file_contents_batch()andfetch_file_contents_with_base(), file paths from PRs are interpolated directly into GraphQLexpressionstrings using f-strings:If a filename contains double quotes (e.g.,
src/"quoted"/file.py) or backslashes (common in Windows-originated PRs), the resulting GraphQL query will have broken syntax. This causes the entire batch file fetch to fail, and all files in the PR receive a score of 0 (sincecontent_pairwill be None).Fix
Escape backslashes and double quotes in file paths before interpolation:
Applied to both
fetch_file_contents_batch()andfetch_file_contents_with_base().Impact
Without this fix, any PR containing files with special characters in their paths would silently score 0 for all files in the batch fetch, potentially zeroing out an entire PR score.