Skip to content

Preview/spanner googlesql#6

Open
gabrielcipriano wants to merge 38 commits intomainfrom
preview/spanner-googlesql
Open

Preview/spanner googlesql#6
gabrielcipriano wants to merge 38 commits intomainfrom
preview/spanner-googlesql

Conversation

@gabrielcipriano
Copy link
Collaborator

No description provided.

}

export function escapeSingleQuotesGooglesql(str: string): string {
return str.replace(/'/g, "\\'");

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix

AI about 1 year ago

To fix the problem, we need to ensure that backslashes in the input string are also escaped. This can be done by first replacing all backslashes with double backslashes and then replacing single quotes with a backslash followed by a single quote. This approach ensures that both backslashes and single quotes are properly escaped.

Suggested changeset 1
drizzle-kit/src/utils.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/drizzle-kit/src/utils.ts b/drizzle-kit/src/utils.ts
--- a/drizzle-kit/src/utils.ts
+++ b/drizzle-kit/src/utils.ts
@@ -373,3 +373,3 @@
 export function escapeSingleQuotesGooglesql(str: string): string {
-	return str.replace(/'/g, "\\'");
+	return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
 }
EOF
@@ -373,3 +373,3 @@
export function escapeSingleQuotesGooglesql(str: string): string {
return str.replace(/'/g, "\\'");
return str.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
}
Copilot is powered by AI and may make mistakes. Always verify output.
}

escapeString(str: string): string {
return `'${str.replace(/'/g, "\\'")}'`;

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix

AI about 1 year ago

To fix the problem, we need to ensure that the escapeString method correctly escapes backslashes in addition to single quotes. This can be achieved by first replacing backslashes with double backslashes and then replacing single quotes with escaped single quotes. This ensures that all occurrences of these characters are properly escaped.

The best way to fix the problem without changing existing functionality is to update the escapeString method to use two replace calls: one for backslashes and one for single quotes. This approach ensures that both characters are handled correctly.

Suggested changeset 1
drizzle-orm/src/googlesql/dialect.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/drizzle-orm/src/googlesql/dialect.ts b/drizzle-orm/src/googlesql/dialect.ts
--- a/drizzle-orm/src/googlesql/dialect.ts
+++ b/drizzle-orm/src/googlesql/dialect.ts
@@ -102,3 +102,3 @@
 	escapeString(str: string): string {
-		return `'${str.replace(/'/g, "\\'")}'`;
+		return `'${str.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
 	}
EOF
@@ -102,3 +102,3 @@
escapeString(str: string): string {
return `'${str.replace(/'/g, "\\'")}'`;
return `'${str.replace(/\\/g, "\\\\").replace(/'/g, "\\'")}'`;
}
Copilot is powered by AI and may make mistakes. Always verify output.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant