MCPcopy Index your code
hub / github.com/deepnote/deepnote / escapePythonString

Function escapePythonString

packages/blocks/src/blocks/python-utils.ts:1–13  ·  view source on GitHub ↗
(value: string)

Source from the content-addressed store, hash-verified

1export function escapePythonString(value: string): string {
2 // Escape characters that would otherwise terminate or invalidate a single-quoted
3 // Python string literal: backslash, single quote, LF, CR, and NUL.
4 const escaped = value
5 .replaceAll('\\', '\\\\')
6 .replaceAll("'", "\\'")
7 .replaceAll('\n', '\\n')
8 .replaceAll('\r', '\\r')
9 .replaceAll('\x00', '\\x00')
10
11 // Wrap the escaped string in single quotes
12 return `'${escaped}'`
13}
14
15export function sanitizePythonVariableName(
16 name: string,

Calls

no outgoing calls

Tested by

no test coverage detected