From 4cccf929eb7345c2e9959bf15b9aa1200ea54cdd Mon Sep 17 00:00:00 2001 From: "Alexis (Poliorcetics) Bourget" Date: Sat, 6 Sep 2025 19:50:24 +0200 Subject: [PATCH] fix: when parsing `python_string`s 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. --- kitty/conf/utils.py | 1 + kitty_tests/options.py | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/kitty/conf/utils.py b/kitty/conf/utils.py index 9cccec7dd..946052730 100644 --- a/kitty/conf/utils.py +++ b/kitty/conf/utils.py @@ -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 diff --git a/kitty_tests/options.py b/kitty_tests/options.py index 169b8aed1..4eb56ff6e 100644 --- a/kitty_tests/options.py +++ b/kitty_tests/options.py @@ -234,6 +234,10 @@ def conf_parsing(self): self.ae(opts.mouse_hide_wait[3], True) self.ae(opts.color23, Color(255, 0, 0)) self.assertFalse(opts.keyboard_modes[''].keymap) + opts = p("url_excluded_characters '''") + self.ae(opts.url_excluded_characters, "'''") + opts = p("url_excluded_characters abc'") + self.ae(opts.url_excluded_characters, "abc'") opts = p('clear_all_shortcuts y', 'map f1 next_window') self.ae(len(opts.keyboard_modes[''].keymap), 1) opts = p('clear_all_mouse_actions y', 'mouse_map left click ungrabbed mouse_click_url_or_select')