Fix #2561: Escape control characters in assertion error messages#2690
Conversation
af6075c to
1d213ef
Compare
1d213ef to
1998896
Compare
39c88be to
eb5917c
Compare
|
Rewrote at eb5917c per your comments — single StringBuilder pass, fast path for the common no-special-chars case:
Micro-bench (50k calls, PS 7.6.2):
Side benefit: now escapes the entire 0x00..0x1F range instead of just 8 hand-listed chars — vertical tab, FS/GS/RS/US etc. also become visible. Tests: 69/69 green on both PS 7.6 and PS 5.1. |
f923523 to
d89c54d
Compare
|
Moved the hot loop to Correctness on 200,000-char input with 10k each of NUL/TAB/LF/ESC scattered through it — all 40k control chars converted to U+2400..U+241B, zero raw control chars left. Bench (1k iterations, PS 7.6.2):
For a typical short error-message string fast and slow paths are both ~0.08 ms per call. 69/69 tests green on PS 7.6 and PS 5.1. |
Format-String2 now escapes control characters as Unicode control pictures so they are visible in error messages. Characters like ESC (used in ANSI sequences) now display as their Unicode symbol instead of being invisible. Copilot-generated fix. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
d89c54d to
6f6e181
Compare
|
Good call — pulled the function Format-String2 ($Value) {
if ($null -eq $Value -or $Value.Length -eq 0) {
return '<empty>'
}
"'" + [Pester.Formatter]::EscapeControlChars($Value) + "'"
} |
Fix #2561
Format-String2 now escapes control characters as Unicode control pictures so they are visible in error messages. Characters like ESC (used in ANSI sequences) now display as their Unicode symbol instead of being invisible.
Copilot-generated fix.
Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com