Repository: microsoft/terminal (language: cpp)

Issue:
Escape sequences in unit test log comments are being interpreted
### Windows Terminal version

Commit 9b21b78feea9ff0a0b9ff2c8fa4b4aa5602d3889

### Windows build number

10.0.19045.4780

### Other Software

_No response_

### Steps to reproduce

1. Get the latest source (I suspect it needs to be 4c018efd641dd71502e4019078bb6325c68b7f9a or later)
2. Build the project
3. From a cmd shell[^1], run the `VtResize` unit test.
    
    ```
    runut /name:ScreenBufferTests::VtResize
    ````

[^1]: I'm not sure it _has_ to be a cmd shell, but that's all I ever use.


### Expected Behavior

You should see the test log output as usual.

### Actual Behavior

The output appears to be clamped to a corner of the screen.

![image](https://github.com/user-attachments/assets/bdcedc1b-98c5-431c-a563-21b7e3458ef3)

If you have a look at the source for that test, you'll notice there are escape sequences in several of the log comments. For example, see here:
https://github.com/microsoft/terminal/blob/main/src/host/ut_host/ScreenBufferTests.cpp#L1173-L1176

I'm guessing what's happening is that those escape sequences are now being interpreted, which causes the conhost buffer to be resized, and that ends up screwing up the output.

This only started happening very recently, and that test has been around for ages, so I'm assuming it's got something to do with the TAEF upgrade in PR #16595.




Discussion / hints:
Ugh, I was just thinking about this today. Some version of it has been lurking forever, and I was wondering if our test framework has a way for us to override the output formatter. 
It may be easier just to go through and escape the few places that are using control characters in those log comments. I'm hoping there aren't that many, because I noticed that some of them were already escaped. Just patching the `VtResize` test was enough to get a normalish run, although at one point the terminal minimized itself, so I'm assuming there's also at least one unescaped `CSI 2 t` sequence lurking somewhere.
All of the ones that validate ReturnResponse, as well as the mouse encoding ones, will fall into that bucket too. You’re probably right, however.

Fix patch:
diff --git a/src/host/ut_host/ScreenBufferTests.cpp b/src/host/ut_host/ScreenBufferTests.cpp
index d1fe5a31962..beaab2c3047 100644
--- a/src/host/ut_host/ScreenBufferTests.cpp
+++ b/src/host/ut_host/ScreenBufferTests.cpp
@@ -1105,7 +1105,7 @@ void ScreenBufferTests::VtResize()
     auto initialViewWidth = si.GetViewport().Width();
 
     Log::Comment(NoThrowString().Format(
-        L"Write '\x1b[8;30;80t'"
+        L"Write '\\x1b[8;30;80t'"
         L" The Screen buffer height should remain unchanged, but the width should be 80 columns"
         L" The viewport should be w,h=80,30"));
 
@@ -1127,7 +1127,7 @@ void ScreenBufferTests::VtResize()
     initialViewWidth = newViewWidth;
 
     Log::Comment(NoThrowString().Format(
-        L"Write '\x1b[8;40;80t'"
+        L"Write '\\x1b[8;40;80t'"
         L" The Screen buffer height should remain unchanged, but the width should be 80 columns"
         L" The viewport should be w,h=80,40"));
 
@@ -1149,7 +1149,7 @@ void ScreenBufferTests::VtResize()
     initialViewWidth = newViewWidth;
 
     Log::Comment(NoThrowString().Format(
-        L"Write '\x1b[8;40;90t'"
+        L"Write '\\x1b[8;40;90t'"
         L" The Screen buffer height should remain unchanged, but the width should be 90 columns"
         L" The viewport should be w,h=90,40"));
 
@@ -1171,7 +1171,7 @@ void ScreenBufferTests::VtResize()
     initialViewWidth = newViewWidth;
 
     Log::Comment(NoThrowString().Format(
-        L"Write '\x1b[8;12;12t'"
+        L"Write '\\x1b[8;12;12t'"
         L" The Screen buffer height should remain unchanged, but the width should be 12 columns"
         L" The viewport should be w,h=12,12"));
 


Test patch: