Files
9ff08590cb fix(windows): make PowerShell scripts ASCII-only (PS 5.1 parse crash) (#192)
Fixes #183. Fixes #185. BOM-less .ps1 files are decoded by Windows PowerShell
5.1 with the system ANSI code page, not UTF-8, so the em-dash (U+2014) and arrow
(U+2192) in hunt.ps1 / install.ps1 / install-community-skills.ps1 became 'â€"'
and broke parsing — every new PowerShell window threw parser errors and the hunt
function was never defined.

Replace the two non-ASCII characters with ASCII equivalents ('-' and '->'); the
scripts are now pure ASCII, so PS 5.1 parses them regardless of code page and no
BOM is needed. tests/test_ps1_ascii.py locks the invariant in on CI.

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
2026-11-20 21:23:27 +05:30

29 lines
1.0 KiB
Python

"""Guard for issues #183/#185: PowerShell scripts must stay pure ASCII.
Windows PowerShell 5.1 decodes BOM-less .ps1 files with the system ANSI code
page, not UTF-8, so any non-ASCII character (em-dash, arrows) corrupts the
script and breaks parsing when hunt.ps1 is dot-sourced from $PROFILE. Keeping
the .ps1 sources ASCII-only sidesteps the whole problem without a BOM.
"""
import glob
import os
import unittest
_REPO = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
class Ps1AsciiTests(unittest.TestCase):
def test_all_ps1_scripts_are_ascii(self):
offenders = {}
for path in glob.glob(os.path.join(_REPO, "scripts", "*.ps1")):
text = open(path, encoding="utf-8").read()
bad = sorted({c for c in text if ord(c) > 127})
if bad:
offenders[os.path.basename(path)] = [f"U+{ord(c):04X} {c!r}" for c in bad]
self.assertEqual(offenders, {},
f"non-ASCII in .ps1 breaks Windows PowerShell 5.1: {offenders}")
if __name__ == "__main__":
unittest.main()