MCPcopy Create free account
hub / github.com/bytebase/bytebase / escapeMongoDBCollectionName

Function escapeMongoDBCollectionName

frontend/src/utils/v1/sql.ts:138–148  ·  view source on GitHub ↗
(name: string)

Source from the content-addressed store, hash-verified

136};
137
138const escapeMongoDBCollectionName = (name: string) => {
139 // The backend wraps --eval in single quotes for shell execution and escapes
140 // single quotes with '"'"'. To avoid conflicts, we:
141 // 1. Use double quotes for the collection name string
142 // 2. Escape backslashes and double quotes for JavaScript
143 // 3. Replace single quotes with Unicode escape \u0027 so the shell doesn't see them
144 return name
145 .replace(/\\/g, "\\\\")
146 .replace(/"/g, '\\"')
147 .replace(/'/g, "\\u0027");
148};
149
150const wrapSQLIdentifier = (id: string, engine: Engine) => {
151 if (engine === Engine.MSSQL) {

Calls

no outgoing calls

Tested by

no test coverage detected