fix(django-google-spanner): escape backslashes in quote_value#17537
Open
saddamr3e wants to merge 1 commit into
Open
fix(django-google-spanner): escape backslashes in quote_value#17537saddamr3e wants to merge 1 commit into
saddamr3e wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request updates the quote_value method in DatabaseSchemaEditor to correctly escape string values for Cloud Spanner (GoogleSQL) by using backslashes instead of doubling single quotes. It also adds corresponding unit tests to verify that backslashes and single quotes are properly escaped. There are no review comments, so I have no feedback to provide.
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.
DatabaseSchemaEditor.quote_valueinlines string values into DDL (Spanner doesn't accept bind parameters in those positions) and escapes them with ANSI quote doubling. Cloud Spanner runs GoogleSQL, which escapes a quote with a backslash and treats the backslash itself as an escape character, so doubling is the wrong convention here. A plain apostrophe such as a default ofO'Brienrenders as'O''Brien'and fails to parse, and a value that contains a backslash escapes the closing quote and runs off the end of the literal. With a crafted default like\' OR 1=1 --the output becomes'\'' OR 1=1 -- ', where the\'is an escaped quote and the following quote closes the string, leavingOR 1=1as live SQL. I noticed it because the generated-column anddb_defaultpaths a few lines up in the same file already escape the GoogleSQL way, whilequote_value(andprepare_default, which calls it) still doubled. The change movesquote_valueto the same backslash escaping so the value stays inside its literal.