Skip to content
This repository was archived by the owner on May 2, 2026. It is now read-only.

Commit 9ef834c

Browse files
committed
fix: update shell_safe function to improve string literal escaping
1 parent 1ce2d27 commit 9ef834c

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

viu_media/core/utils/formatter.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,19 @@ def shell_safe(text: Optional[str]) -> str:
186186
"""
187187
Escapes a string for safe inclusion in a Python script string literal.
188188
This is used when generating Python cache scripts with embedded text content.
189-
190-
For Python triple-quoted strings, we need to:
189+
190+
For Python string literals, we need to:
191191
- Escape backslashes first (so existing backslashes don't interfere)
192-
- Escape triple quotes (to not break the string literal)
193-
- Remove or replace problematic characters
192+
- Escape double quotes (to not break double-quoted string literals)
193+
- Escape single quotes (to not break single-quoted string literals)
194194
"""
195195
if not text:
196196
return ""
197197
# Escape backslashes first
198198
result = text.replace("\\", "\\\\")
199-
# Escape triple quotes (both types) for Python triple-quoted string literals
200-
result = result.replace('"""', r'\"\"\"')
201-
result = result.replace("'''", r"\'\'\'")
199+
# Escape both quote types for safe inclusion in any string literal
200+
result = result.replace('"', r"\"")
201+
result = result.replace("'", r"\'")
202202
return result
203203

204204

0 commit comments

Comments
 (0)