mirror of
https://github.com/Benexl/FastAnime.git
synced 2026-04-28 11:53:08 -07:00
Merge branch 'master' into copilot/improve-installation-section
This commit is contained in:
@@ -187,18 +187,18 @@ def shell_safe(text: Optional[str]) -> str:
|
|||||||
Escapes a string for safe inclusion in a Python script string literal.
|
Escapes a string for safe inclusion in a Python script string literal.
|
||||||
This is used when generating Python cache scripts with embedded text content.
|
This is used when generating Python cache scripts with embedded text content.
|
||||||
|
|
||||||
For Python triple-quoted strings, we need to:
|
For Python string literals, we need to:
|
||||||
- Escape backslashes first (so existing backslashes don't interfere)
|
- Escape backslashes first (so existing backslashes don't interfere)
|
||||||
- Escape triple quotes (to not break the string literal)
|
- Escape double quotes (to not break double-quoted string literals)
|
||||||
- Remove or replace problematic characters
|
- Escape single quotes (to not break single-quoted string literals)
|
||||||
"""
|
"""
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
# Escape backslashes first
|
# Escape backslashes first
|
||||||
result = text.replace("\\", "\\\\")
|
result = text.replace("\\", "\\\\")
|
||||||
# Escape triple quotes (both types) for Python triple-quoted string literals
|
# Escape both quote types for safe inclusion in any string literal
|
||||||
result = result.replace('"""', r'\"\"\"')
|
result = result.replace('"', r"\"")
|
||||||
result = result.replace("'''", r"\'\'\'")
|
result = result.replace("'", r"\'")
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user