mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-15 21:14:35 +02:00
fix: when parsing python_strings options, don't fail if ' is last
Previously, if the last character was `'` parsing would fail: from `abc'` it would produce the literal `'''abc''''`, which has one too many unescaped single quote at the end. This also fixes the issue for solo `'''`, where before it would produce `''''\\'''''`, again with one too many single quote at the end. I added tests for both cases.
This commit is contained in:
@@ -127,6 +127,7 @@ def to_cmdline(x: str, expand: bool = True) -> list[str]:
|
||||
|
||||
def python_string(text: str) -> str:
|
||||
from ast import literal_eval
|
||||
text = (text[:-1] + "\\'") if text.endswith("'") else text
|
||||
ans: str = literal_eval("'''" + text.replace("'''", "'\\''") + "'''")
|
||||
return ans
|
||||
|
||||
|
||||
Reference in New Issue
Block a user