Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
fix: escape special characters (#9785)
h3n4l7084bc8d871c
diff --git a/backend/plugin/db/mongodb/mongodb.go b/backend/plugin/db/mongodb/mongodb.goindex ff97b5b347..dc75ffd847 100644--- a/backend/plugin/db/mongodb/mongodb.go+++ b/backend/plugin/db/mongodb/mongodb.go@@ -191,8 +191,11 @@ func (driver *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement striif queryContext != nil && queryContext.Limit > 0 {limit = fmt.Sprintf(".slice(0, %d)", queryContext.Limit)}- evalArg = fmt.Sprintf(`"a = %s; if (typeof a.toArray === 'function') {print(EJSON.stringify(a.toArray()%s)); sleep(0);} else {print(EJSON.stringify(a)); sleep(0);}"`, strings.TrimRight(statement, " \t\n\r\f;"), limit)+ evalArg = fmt.Sprintf(`a = %s; if (typeof a.toArray === 'function') {print(EJSON.stringify(a.toArray()%s)); sleep(0);} else {print(EJSON.stringify(a)); sleep(0);}`, strings.TrimRight(statement, " \t\n\r\f;"), limit)}+ // We will use single quotes for the evalArg, so we need to escape the single quotes in the statement.+ evalArg = strings.ReplaceAll(evalArg, `'`, `'"'`)+ evalArg = fmt.Sprintf(`'%s'`, evalArg)fileName := fmt.Sprintf("mongodb-query-%s-%s", driver.connCfg.ConnectionDatabase, uuid.New().String())defer func() {@@ -205,7 +208,7 @@ func (driver *Driver) QueryConn(ctx context.Context, _ *sql.Conn, statement stri"--quiet","--eval",evalArg,- ">>",+ ">",fileName,}