(value: string)
| 1 | export 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 | |
| 15 | export function sanitizePythonVariableName( |
| 16 | name: string, |
no outgoing calls
no test coverage detected