Verify icon indicating copy to clipboard operation
Verify copied to clipboard

Current directory scrubbing regression when path is inside ANSI sequence

Open hojmark opened this issue 5 months ago • 3 comments

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

hojmark avatar Nov 16 '25 14:11 hojmark

can you share more on your scenario. in what context do you have that a path is wrapped in those characters?

SimonCropp avatar Nov 16 '25 19:11 SimonCropp

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.

hojmark avatar Nov 16 '25 19:11 hojmark

i dont know how to support both this https://github.com/VerifyTests/Verify/issues/1589 and your scenario.

ideas?

SimonCropp avatar Nov 24 '25 23:11 SimonCropp