diff --git a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp index 17c771830..dcdbb32b3 100644 --- a/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp +++ b/src/interactivity/win32/ut_interactivity_win32/UiaTextRangeTests.cpp @@ -1346,4 +1346,27 @@ class UiaTextRangeTests VERIFY_SUCCEEDED(utr->ScrollIntoView(alignToTop)); } } + + TEST_METHOD(BlockRange) + { + // This test replicates GH#7960. + // It was caused by _blockRange being uninitialized, resulting in it occasionally being set to true. + // Additionally, all of the ctors _except_ the copy ctor initialized it. So this would be more apparent + // when calling Clone. + Microsoft::WRL::ComPtr utr; + THROW_IF_FAILED(Microsoft::WRL::MakeAndInitialize(&utr, _pUiaData, &_dummyProvider)); + VERIFY_IS_FALSE(utr->_blockRange); + + Microsoft::WRL::ComPtr clone1; + THROW_IF_FAILED(utr->Clone(&clone1)); + + UiaTextRange* cloneUtr1 = static_cast(clone1.Get()); + VERIFY_IS_FALSE(cloneUtr1->_blockRange); + cloneUtr1->_blockRange = true; + + Microsoft::WRL::ComPtr clone2; + cloneUtr1->Clone(&clone2); + UiaTextRange* cloneUtr2 = static_cast(clone2.Get()); + VERIFY_IS_TRUE(cloneUtr2->_blockRange); + } }; diff --git a/src/types/UiaTextRangeBase.cpp b/src/types/UiaTextRangeBase.cpp index 3d61d23f3..e254134f3 100644 --- a/src/types/UiaTextRangeBase.cpp +++ b/src/types/UiaTextRangeBase.cpp @@ -117,6 +117,7 @@ try _end = a._end; _pData = a._pData; _wordDelimiters = a._wordDelimiters; + _blockRange = a._blockRange; UiaTracing::TextRange::Constructor(*this); return S_OK; diff --git a/src/types/UiaTextRangeBase.hpp b/src/types/UiaTextRangeBase.hpp index 7122cefcf..d8d7fcb1d 100644 --- a/src/types/UiaTextRangeBase.hpp +++ b/src/types/UiaTextRangeBase.hpp @@ -137,7 +137,7 @@ namespace Microsoft::Console::Types // NOTE: _start is inclusive, but _end is exclusive COORD _start{}; COORD _end{}; - bool _blockRange; + bool _blockRange{}; // This is used by tracing to extract the text value // that the UiaTextRange currently encompasses.