Skip to content

Commit 51225c7

Browse files
committed
critical fix!
1 parent 02eb6ec commit 51225c7

1 file changed

Lines changed: 20 additions & 2 deletions

File tree

chomp/src/chomp/repack.py

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@
7272
)
7373

7474

75+
def _replace_url_in_text(text: str, old_url: str, new_url: str) -> str:
76+
"""
77+
Replace old_url with new_url in .ps1 text.
78+
79+
If new_url contains a PowerShell subexpression ``$(...)`` and the URL
80+
was wrapped in single quotes, re-quote that token with double quotes so
81+
the subexpression actually expands at runtime. Single-quoted strings in
82+
PowerShell are literal — ``$()`` is never evaluated inside them.
83+
"""
84+
if "$(" not in new_url:
85+
return text.replace(old_url, new_url)
86+
# Single-quoted token: 'https://...' → "$(Split-Path ...)\files\foo.exe"
87+
text = text.replace(f"'{old_url}'", f'"{new_url}"')
88+
# Unquoted or already double-quoted occurrences
89+
text = text.replace(old_url, new_url)
90+
return text
91+
92+
7593
# ── Helpers ───────────────────────────────────────────────────────────────────
7694

7795

@@ -195,7 +213,7 @@ def _rewrite_ps1(
195213
if mappings:
196214
new_text = text
197215
for m in mappings:
198-
new_text = new_text.replace(m["old_url"], m["new_url"])
216+
new_text = _replace_url_in_text(new_text, m["old_url"], m["new_url"])
199217
if new_text != text:
200218
ps1.write_text(new_text, encoding="utf-8")
201219
vlog(f"Rewrote {len(mappings)} URL(s) in {ps1.name} [{mode}]")
@@ -328,7 +346,7 @@ def build_nupkg(
328346
# Rewrite URLs
329347
text = ps1.read_text(encoding="utf-8", errors="replace")
330348
for m in ps1_maps:
331-
text = text.replace(m["old_url"], m["new_url"])
349+
text = _replace_url_in_text(text, m["old_url"], m["new_url"])
332350
ps1.write_text(text, encoding="utf-8")
333351
# Embed installer files (internalize only)
334352
if mode == "internalize":

0 commit comments

Comments
 (0)