Skip to content

Commit 1173718

Browse files
authored
Resolve shebang templates case-insensitively. (#367)
Fixes #366
1 parent 3fbb7df commit 1173718

2 files changed

Lines changed: 12 additions & 0 deletions

File tree

src/manage/scriptutils.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ def _replace_templates(cmd, line, windowed):
129129
if not m:
130130
return None, None
131131

132+
template_key = None
132133
full_key = (m.group(1) + m.group(2)).strip()
133134
if full_key in cmd.shebang_templates:
134135
template_key = full_key
@@ -137,6 +138,15 @@ def _replace_templates(cmd, line, windowed):
137138
template_key = m.group(1)
138139
suffix = m.group(2)
139140
else:
141+
# Also map case-insensitive keys back to their original casing
142+
keys_cf = {k.casefold(): k for k in cmd.shebang_templates}
143+
template_key = keys_cf.get(full_key.casefold())
144+
suffix = ""
145+
if not template_key:
146+
template_key = keys_cf.get(m.group(1).casefold())
147+
suffix = m.group(2)
148+
149+
if not template_key:
140150
return None, None
141151

142152
new_cmd = cmd.shebang_templates[template_key]

tests/test_scriptutils.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,9 @@ def test_quote_args(args, expect):
288288
("#! /usr/bin/python3", "PythonCore3", None),
289289
("#! /usr/bin/pythonw3", "PythonCore3", None),
290290
("#! custom", None, "#!CUSTOM"),
291+
("#! CUSTOM", None, "#!CUSTOM"),
291292
("#! full line custom", None, "#!CUSTOM2"),
293+
("#! FULL LINE CUSTOM", None, "#!CUSTOM2"),
292294
("#!full line custom with extra", None, None),
293295
("custom", None, None),
294296
("full line custom", None, None),

0 commit comments

Comments
 (0)