Skip to content

powershell: escape all five single-quote characters - #258

Merged
casperdcl merged 2 commits into
tqdm:mainfrom
dylanpulver:powershell-escape-all-quote-chars
Sep 1, 2026
Merged

casperdcl merged 2 commits into
tqdm:mainfrom
dylanpulver:powershell-escape-all-quote-chars

Conversation

@dylanpulver

@dylanpulver dylanpulver commented Sep 1, 2026 •

Copy link
Copy Markdown
Contributor

PowerShell closes a verbatim string literal on any of five characters — U+0027, U+2018, U+2019, U+201A and U+201B (Language Specification 3.0, §2.3.5.1.1 single-quote-character). _powershell_escape doubles only the first three, so help text, an option string or a command name containing U+201A or U+201B emits a script PowerShell cannot parse.

U+201A is the ordinary opening single quote in German, Czech, Slovak, Polish and Hungarian typography, so this is reachable from plain help= text.

Measured with pwsh 7.6.5, parsing the output of shtab.complete(parser, "powershell") via [Parser]::ParseFile — same script, same binary, before and after:

help text contains       before          after
U+0027  it's fine        0 errors        0 errors
U+2018  a 'quoted' word  0 errors        0 errors
U+201A  German ,quoted'  5 errors        0 errors   <- Unexpected token ... in expression or statement
U+201B  odd 'quoted'     5 errors        0 errors
no quote characters      0 errors        0 errors

Doubling is the right remedy for all five, not just a workaround: 'x<C><C>y' evaluates to x<C>y with the original codepoint preserved, confirmed in pwsh for each of the five (8218 and 8219 come back intact).

How this was found: not from a bug report — a systematic pass over escaping/quoting tables in CLI tooling, checking each against the grammar it claims to implement. This one is a hand-written character set with no test covering it, so a character the grammar lists and the set omits cannot fail anything.

_powershell_escape currently has no test at all; the new one is parametrized over all five characters so the set can't silently fall behind again.

Verified: pytest tests/, pwsh on PATH for every run — 100 passed / 56 skipped before, 105 passed / 56 skipped after (the 5 new parametrized cases). Reverting only shtab/__init__.py and keeping the test: 2 failed / 103 passed / 56 skipped. Two naive alternatives also fail it — normalising all five to an ASCII apostrophe (4 failed; it parses but corrupts the text) and adding only U+201A (1 failed). pre-commit run on both changed files: all 22 hooks pass.

Not tested: only pwsh 7.6.5 on macOS/arm64. Windows PowerShell 5.1 was not available to me; the grammar is the same but I did not confirm it there.

AI assistance: this change was written with Claude Code (model Claude Opus 5). I reviewed the diff and ran everything reported above.

dylanpulver and others added 2 commits September 1, 2026 23:05
Co-authored-by: Claude <noreply@anthropic.com>
@casperdcl
casperdcl force-pushed the powershell-escape-all-quote-chars branch from cfc783d to 0d60059 Compare September 1, 2026 22:06

@casperdcl casperdcl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.83%. Comparing base (2c51f5e) to head (0d60059).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #258   +/-   ##
=======================================
  Coverage   87.83%   87.83%           
=======================================
  Files           4        4           
  Lines         666      666           
  Branches      138      138           
=======================================
  Hits          585      585           
  Misses         43       43           
  Partials       38       38           
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@casperdcl
casperdcl merged commit e1ab406 into tqdm:main Sep 1, 2026
9 checks passed

This branch was successfully deployed

1 active deployment
pypi — 0d600592 Deployed Sep 1, 2026 by casperdcl via deploy #1350
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants