mirror of
https://github.com/microsoft/terminal.git
synced 2026-04-06 06:09:50 +00:00
Compare commits
2 Commits
dev/pabhoj
...
dev/miniks
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b0954c07de | ||
|
|
f31a3c1f74 |
@@ -303,6 +303,7 @@ void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region)
|
||||
const size_t lengthToWrite,
|
||||
const COORD startingCoordinate,
|
||||
size_t& cellsModified) noexcept
|
||||
try
|
||||
{
|
||||
const auto& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
|
||||
|
||||
@@ -313,3 +314,4 @@ void WriteToScreen(SCREEN_INFORMATION& screenInfo, const Viewport& region)
|
||||
|
||||
return FillConsoleOutputCharacterWImpl(OutContext, wchs.at(0), lengthToWrite, startingCoordinate, cellsModified);
|
||||
}
|
||||
CATCH_RETURN()
|
||||
|
||||
@@ -10,6 +10,24 @@ class FillOutputTests
|
||||
BEGIN_TEST_CLASS(FillOutputTests)
|
||||
END_TEST_CLASS()
|
||||
|
||||
// Adapted from repro in GH#4258
|
||||
TEST_METHOD(FillWithInvalidCharacterA)
|
||||
{
|
||||
VERIFY_WIN32_BOOL_SUCCEEDED(SetConsoleOutputCP(50220));
|
||||
auto handle = GetStdOutputHandle();
|
||||
const COORD pos{ 0, 0 };
|
||||
DWORD written = 0;
|
||||
const char originalCh = 14;
|
||||
VERIFY_WIN32_BOOL_SUCCEEDED(FillConsoleOutputCharacterA(handle, originalCh, 1, pos, &written));
|
||||
VERIFY_ARE_EQUAL(1u, written);
|
||||
|
||||
char readCh = 42; // don't use null (the expected) or 14 (the actual) to ensure that it is read out.
|
||||
DWORD read = 0;
|
||||
VERIFY_WIN32_BOOL_SUCCEEDED(ReadConsoleOutputCharacterA(handle, &readCh, 1, pos, &read));
|
||||
VERIFY_ARE_EQUAL(1u, read);
|
||||
VERIFY_ARE_EQUAL(0, readCh, L"Null should be read back as the conversion from the invalid original character.");
|
||||
}
|
||||
|
||||
TEST_METHOD(WriteNarrowGlyphAscii)
|
||||
{
|
||||
HANDLE hConsole = GetStdOutputHandle();
|
||||
|
||||
@@ -34,3 +34,23 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned"
|
||||
LOG_CAUGHT_EXCEPTION(); \
|
||||
return false; \
|
||||
}
|
||||
|
||||
// MultiByteToWideChar has a bug in it where it can return 0 and then not set last error.
|
||||
// WIL has a fit if the last error is 0 when a bool false is returned.
|
||||
// This macro doesn't have a fit. It just reports E_UNEXPECTED instead.
|
||||
#define THROW_LAST_ERROR_IF_AND_IGNORE_BAD_GLE(condition) \
|
||||
do \
|
||||
{ \
|
||||
if (condition) \
|
||||
{ \
|
||||
const auto gle = ::GetLastError(); \
|
||||
if (gle) \
|
||||
{ \
|
||||
THROW_WIN32(gle); \
|
||||
} \
|
||||
else \
|
||||
{ \
|
||||
THROW_HR(E_UNEXPECTED); \
|
||||
} \
|
||||
} \
|
||||
} while (0, 0) \
|
||||
|
||||
@@ -39,7 +39,7 @@ static const WORD leftShiftScanCode = 0x2A;
|
||||
|
||||
// Ask how much space we will need.
|
||||
int const iTarget = MultiByteToWideChar(codePage, 0, source.data(), iSource, nullptr, 0);
|
||||
THROW_LAST_ERROR_IF(0 == iTarget);
|
||||
THROW_LAST_ERROR_IF_AND_IGNORE_BAD_GLE(0 == iTarget);
|
||||
|
||||
size_t cchNeeded;
|
||||
THROW_IF_FAILED(IntToSizeT(iTarget, &cchNeeded));
|
||||
@@ -49,7 +49,7 @@ static const WORD leftShiftScanCode = 0x2A;
|
||||
out.resize(cchNeeded);
|
||||
|
||||
// Attempt conversion for real.
|
||||
THROW_LAST_ERROR_IF(0 == MultiByteToWideChar(codePage, 0, source.data(), iSource, out.data(), iTarget));
|
||||
THROW_LAST_ERROR_IF_AND_IGNORE_BAD_GLE(0 == MultiByteToWideChar(codePage, 0, source.data(), iSource, out.data(), iTarget));
|
||||
|
||||
// Return as a string
|
||||
return out;
|
||||
|
||||
Reference in New Issue
Block a user