Current directory scrubbing regression when path is inside ANSI sequence
Describe the bug
Scrubbing of the current directory no longer works if the path is inside an ANSI sequence. I have located the regression to first occur in Verify.NUnit 31.5.0 and onwards.
The scrubbing works if the path is not inside an ANSI sequence
Minimal Repro
[Test]
public Task Path_in_ansi_sequence_is_not_scrubbed() {
var currentDirectory = Directory.GetCurrentDirectory();
const string boldOn = "\u001b[1m";
const string reset = "\u001b[0m";
return Verify( $"Path: {boldOn}{currentDirectory}/myfile.yaml{reset}" );
}
Verify.NUnit 31.4.3:
Path: [1m{CurrentDirectory}myfile.yaml[0m
Verify.NUnit 31.5.0 (and later):
Path: [1m/home/hojmark/git/drift/src/Cli.Tests/bin/Debug/net10.0/myfile.yaml[0m
can you share more on your scenario. in what context do you have that a path is wrapped in those characters?
Sure. This happens when testing a CLI tool that outputs styled text. It uses ANSI escape sequences (which most terminals support) to format the output - for example bold, colors, etc. One of the values it prints is the path to a file it generated, and that path appear inside an ANSI sequence.
In the real terminal these escape codes aren’t shown; they’re interpreted as styling. But in tests - since the raw output is captured - I’m snapshotting the exact string including the ANSI sequences.
This is important because:
- I want to test the styled output e.g., verifying that certain parts are bold or colored.
- The CLI will have a NO_COLOR mode (in which case I would expect no ANSI sequences), and I want to be able to test both modes.
i dont know how to support both this https://github.com/VerifyTests/Verify/issues/1589 and your scenario.
ideas?