From 8399639dede09f1c92bd199ab4ab68ebccac251b Mon Sep 17 00:00:00 2001 From: Steve Dower Date: Thu, 11 Jun 2026 23:01:01 +0100 Subject: [PATCH] Resolve shebang templates case-insensitively. Fixes #366 --- src/manage/scriptutils.py | 10 ++++++++++ tests/test_scriptutils.py | 2 ++ 2 files changed, 12 insertions(+) diff --git a/src/manage/scriptutils.py b/src/manage/scriptutils.py index 9afaa63..863ac1a 100644 --- a/src/manage/scriptutils.py +++ b/src/manage/scriptutils.py @@ -129,6 +129,7 @@ def _replace_templates(cmd, line, windowed): if not m: return None, None + template_key = None full_key = (m.group(1) + m.group(2)).strip() if full_key in cmd.shebang_templates: template_key = full_key @@ -137,6 +138,15 @@ def _replace_templates(cmd, line, windowed): template_key = m.group(1) suffix = m.group(2) else: + # Also map case-insensitive keys back to their original casing + keys_cf = {k.casefold(): k for k in cmd.shebang_templates} + template_key = keys_cf.get(full_key.casefold()) + suffix = "" + if not template_key: + template_key = keys_cf.get(m.group(1).casefold()) + suffix = m.group(2) + + if not template_key: return None, None new_cmd = cmd.shebang_templates[template_key] diff --git a/tests/test_scriptutils.py b/tests/test_scriptutils.py index f281486..bd35f89 100644 --- a/tests/test_scriptutils.py +++ b/tests/test_scriptutils.py @@ -288,7 +288,9 @@ def test_quote_args(args, expect): ("#! /usr/bin/python3", "PythonCore3", None), ("#! /usr/bin/pythonw3", "PythonCore3", None), ("#! custom", None, "#!CUSTOM"), + ("#! CUSTOM", None, "#!CUSTOM"), ("#! full line custom", None, "#!CUSTOM2"), + ("#! FULL LINE CUSTOM", None, "#!CUSTOM2"), ("#!full line custom with extra", None, None), ("custom", None, None), ("full line custom", None, None),