Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

fix: strip quote (#17237)

h3n4l3f8d759715a0
diff --git a/backend/plugin/db/tidb/sync.go b/backend/plugin/db/tidb/sync.go
index 159ef03011..50935b03c0 100644
--- a/backend/plugin/db/tidb/sync.go
+++ b/backend/plugin/db/tidb/sync.go
@@ -259,7 +259,7 @@ func (d *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetad
return nil, err
}
// Quoted string has a single quote around it and is escaped by QUOTE().
- column.Comment = unquoteMySQLString(column.Comment)
+ column.Comment = stripSingleQuote(column.Comment)
nullableBool, err := util.ConvertYesNo(nullable)
if err != nil {
@@ -384,7 +384,7 @@ func (d *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchemaMetad
return nil, err
}
// Quoted string has a single quote around it and is escaped by QUOTE().
- comment = unquoteMySQLString(comment)
+ comment = stripSingleQuote(comment)
key := db.TableKey{Schema: "", Table: tableName}
switch tableType {
diff --git a/backend/plugin/schema/mysql/generate_migration.go b/backend/plugin/schema/mysql/generate_migration.go
index cb34c0cc01..073546d254 100644
--- a/backend/plugin/schema/mysql/generate_migration.go
+++ b/backend/plugin/schema/mysql/generate_migration.go
@@ -580,7 +580,7 @@ func writeCreateTableWithoutForeignKeys(buf *strings.Builder, tableName string,
if col.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(col.Comment))
+ _, _ = buf.WriteString(col.Comment)
_, _ = buf.WriteString("'")
}
}
@@ -646,7 +646,7 @@ func writeCreateTableWithoutForeignKeys(buf *strings.Builder, tableName string,
}
if table.Comment != "" {
_, _ = buf.WriteString(" COMMENT='")
- _, _ = buf.WriteString(escapeString(table.Comment))
+ _, _ = buf.WriteString(table.Comment)
_, _ = buf.WriteString("'")
}
@@ -720,7 +720,7 @@ func writeAddColumn(buf *strings.Builder, table string, column *storepb.ColumnMe
if column.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(column.Comment))
+ _, _ = buf.WriteString(column.Comment)
_, _ = buf.WriteString("'")
}
@@ -784,7 +784,7 @@ func writeModifyColumn(buf *strings.Builder, table string, column *storepb.Colum
if column.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(column.Comment))
+ _, _ = buf.WriteString(column.Comment)
_, _ = buf.WriteString("'")
}
@@ -845,7 +845,7 @@ func writeCreateIndex(buf *strings.Builder, table string, index *storepb.IndexMe
if index.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(index.Comment))
+ _, _ = buf.WriteString(index.Comment)
_, _ = buf.WriteString("'")
}
@@ -1016,7 +1016,7 @@ func writeAlterTableComment(buf *strings.Builder, tableName, comment string) err
_, _ = buf.WriteString("ALTER TABLE `")
_, _ = buf.WriteString(tableName)
_, _ = buf.WriteString("` COMMENT = '")
- _, _ = buf.WriteString(escapeString(comment))
+ _, _ = buf.WriteString(comment)
_, _ = buf.WriteString("';\n")
return nil
}
@@ -1084,12 +1084,6 @@ func hasAutoIncrement(column *storepb.ColumnMetadata) bool {
return strings.EqualFold(column.GetDefault(), "AUTO_INCREMENT")
}
-func escapeString(s string) string {
- s = strings.ReplaceAll(s, "\\", "\\\\")
- s = strings.ReplaceAll(s, "'", "\\'")
- return s
-}
-
func writeTemporaryViewForDrop(buf *strings.Builder, viewName string, view *storepb.ViewMetadata) error {
// Create a temporary view with SELECT 1 AS column_name structure
// to satisfy other views that depend on this view
diff --git a/backend/plugin/schema/tidb/generate_migration.go b/backend/plugin/schema/tidb/generate_migration.go
index 7c1d775c6e..38744493a0 100644
--- a/backend/plugin/schema/tidb/generate_migration.go
+++ b/backend/plugin/schema/tidb/generate_migration.go
@@ -342,7 +342,7 @@ func writeAlterTableComment(buf *strings.Builder, tableName, comment string) err
_, _ = buf.WriteString("ALTER TABLE `")
_, _ = buf.WriteString(tableName)
_, _ = buf.WriteString("` COMMENT = '")
- _, _ = buf.WriteString(escapeString(comment))
+ _, _ = buf.WriteString(comment)
_, _ = buf.WriteString("';\n\n")
return nil
}
@@ -475,7 +475,7 @@ func writeCreateTableWithoutForeignKeys(buf *strings.Builder, tableName string,
if col.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(col.Comment))
+ _, _ = buf.WriteString(col.Comment)
_, _ = buf.WriteString("'")
}
}
@@ -555,7 +555,7 @@ func writeCreateTableWithoutForeignKeys(buf *strings.Builder, tableName string,
if table.Comment != "" {
_, _ = buf.WriteString(" COMMENT='")
- _, _ = buf.WriteString(escapeString(table.Comment))
+ _, _ = buf.WriteString(table.Comment)
_, _ = buf.WriteString("'")
}
@@ -681,7 +681,7 @@ func writeAddColumn(buf *strings.Builder, table string, column *storepb.ColumnMe
if column.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(column.Comment))
+ _, _ = buf.WriteString(column.Comment)
_, _ = buf.WriteString("'")
}
@@ -730,7 +730,7 @@ func writeModifyColumn(buf *strings.Builder, table string, column *storepb.Colum
if column.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(column.Comment))
+ _, _ = buf.WriteString(column.Comment)
_, _ = buf.WriteString("'")
}
@@ -779,7 +779,7 @@ func writeCreateIndex(buf *strings.Builder, table string, index *storepb.IndexMe
if index.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(index.Comment))
+ _, _ = buf.WriteString(index.Comment)
_, _ = buf.WriteString("'")
}
@@ -1016,12 +1016,6 @@ func hasAutoRandom(column *storepb.ColumnMetadata) bool {
return strings.HasPrefix(column.GetDefault(), "AUTO_RANDOM")
}
-func escapeString(s string) string {
- s = strings.ReplaceAll(s, "\\", "\\\\")
- s = strings.ReplaceAll(s, "'", "\\'")
- return s
-}
-
func writeTemporaryViewForDrop(buf *strings.Builder, viewName string, view *storepb.ViewMetadata) error {
// Create a temporary view with SELECT 1 AS column_name structure
// to satisfy other views that depend on this view
@@ -1123,7 +1117,7 @@ func writeCreateSequence(buf *strings.Builder, sequence *storepb.SequenceMetadat
if sequence.Comment != "" {
_, _ = buf.WriteString(" COMMENT '")
- _, _ = buf.WriteString(escapeString(sequence.Comment))
+ _, _ = buf.WriteString(sequence.Comment)
_, _ = buf.WriteString("'")
}
diff --git a/backend/plugin/schema/tidb/generate_migration_testcontainer_test.go b/backend/plugin/schema/tidb/generate_migration_testcontainer_test.go
index af62b205ea..e694c2ea7f 100644
--- a/backend/plugin/schema/tidb/generate_migration_testcontainer_test.go
+++ b/backend/plugin/schema/tidb/generate_migration_testcontainer_test.go
@@ -195,7 +195,7 @@ CREATE TABLE orders (
migrationDDL: `
-- Create view
CREATE VIEW product_inventory AS
-SELECT
+SELECT
p.id,
p.name,
p.price,
@@ -234,7 +234,7 @@ CREATE TABLE orders (
);
CREATE VIEW product_inventory AS
-SELECT
+SELECT
p.id,
p.name,
p.price,
@@ -268,7 +268,7 @@ CREATE TABLE sales (
migrationDDL: `
-- Create views
CREATE VIEW monthly_sales AS
-SELECT
+SELECT
YEAR(sale_date) AS year,
MONTH(sale_date) AS month,
SUM(sale_amount) AS total_sales
@@ -276,7 +276,7 @@ FROM sales
GROUP BY YEAR(sale_date), MONTH(sale_date);
CREATE VIEW top_products AS
-SELECT
+SELECT
product_name,
COUNT(*) AS sale_count,
SUM(sale_amount) AS total_revenue
@@ -309,7 +309,7 @@ CREATE TABLE sales (
);
CREATE VIEW monthly_sales AS
-SELECT
+SELECT
YEAR(sale_date) AS year,
MONTH(sale_date) AS month,
SUM(sale_amount) AS total_sales
@@ -317,7 +317,7 @@ FROM sales
GROUP BY YEAR(sale_date), MONTH(sale_date);
CREATE VIEW top_products AS
-SELECT
+SELECT
product_name,
COUNT(*) AS sale_count,
SUM(sale_amount) AS total_revenue
@@ -608,7 +608,7 @@ CREATE INDEX idx_region_date ON sales_data(region, sale_date);
-- Create view on partitioned table
CREATE VIEW regional_sales AS
-SELECT
+SELECT
region,
YEAR(sale_date) AS year,
MONTH(sale_date) AS month,
@@ -640,7 +640,7 @@ CREATE TABLE sales_data (
);
CREATE VIEW regional_sales AS
-SELECT
+SELECT
region,
YEAR(sale_date) AS year,
MONTH(sale_date) AS month,
@@ -1360,12 +1360,6 @@ test',
- Multi-line content with various encodings';
`,
migrationDDL: `
--- Restore comment that was removed
-ALTER TABLE special_comments_table MODIFY COLUMN html_field TEXT COMMENT 'HTML content field: <script>alert("XSS test & more");</script>';
-
--- Restore original comment
-ALTER TABLE special_comments_table MODIFY COLUMN data_field JSON COMMENT 'JSON field storing: {"users": ["John O''Connor", "Jane \"Doe\""], "count": 42}';
-
-- Drop table with special comments
DROP TABLE special_comments_table;