Repository: microsoft/terminal (language: cpp)

Issue:
Buffer exports only contain spaces
### Windows Terminal version

main - a01500f

### Windows build number

10.0.22621.819

### Other Software

_No response_

### Steps to reproduce

Open a PowerShell tab, right click on the tab and select Export Text.

### Expected Behavior

The tab content to be exported to a file.

### Actual Behavior

Lots of spaces are exported instead.


Discussion / hints:

Fix patch:
diff --git a/src/cascadia/TerminalControl/ControlCore.cpp b/src/cascadia/TerminalControl/ControlCore.cpp
index 5391ff93e57..780d486c966 100644
--- a/src/cascadia/TerminalControl/ControlCore.cpp
+++ b/src/cascadia/TerminalControl/ControlCore.cpp
@@ -1744,7 +1744,7 @@ namespace winrt::Microsoft::Terminal::Control::implementation
             const auto strEnd = rowText.find_last_not_of(UNICODE_SPACE);
             if (strEnd != decltype(rowText)::npos)
             {
-                str.append(rowText.substr(strEnd + 1));
+                str.append(rowText.substr(0, strEnd + 1));
             }
 
             if (!row.WasWrapForced())
diff --git a/src/cascadia/UnitTests_Control/ControlCoreTests.cpp b/src/cascadia/UnitTests_Control/ControlCoreTests.cpp
index 658d4ca623c..f2d3aba2f88 100644
--- a/src/cascadia/UnitTests_Control/ControlCoreTests.cpp
+++ b/src/cascadia/UnitTests_Control/ControlCoreTests.cpp
@@ -36,6 +36,7 @@ namespace ControlUnitTests
         TEST_METHOD(TestClearScrollback);
         TEST_METHOD(TestClearScreen);
         TEST_METHOD(TestClearAll);
+        TEST_METHOD(TestReadEntireBuffer);
 
         TEST_CLASS_SETUP(ModuleSetup)
         {
@@ -340,4 +341,22 @@ namespace ControlUnitTests
         // The ConptyRoundtripTests test the actual clearing of the contents.
     }
 
+    void ControlCoreTests::TestReadEntireBuffer()
+    {
+        auto [settings, conn] = _createSettingsAndConnection();
+        Log::Comment(L"Create ControlCore object");
+        auto core = createCore(*settings, *conn);
+        VERIFY_IS_NOT_NULL(core);
+        _standardInit(core);
+
+        Log::Comment(L"Print some text");
+        conn->WriteInput(L"This is some text     \r\n");
+        conn->WriteInput(L"with varying amounts  \r\n");
+        conn->WriteInput(L"of whitespace         \r\n");
+
+        Log::Comment(L"Check the buffer contents");
+        VERIFY_ARE_EQUAL(L"This is some text\r\nwith varying amounts\r\nof whitespace\r\n",
+                         core->ReadEntireBuffer());
+    }
+
 }


Test patch: