Skip to content

Commit

Permalink
Comments. I believe I'm okay here.
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 2, 2022
1 parent 522c373 commit e687d17
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 27 deletions.
40 changes: 13 additions & 27 deletions src/host/inputBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,13 @@ void InputBuffer::_ReadBuffer(_Out_ std::deque<std::unique_ptr<IInputEvent>>& ou
}
}

// GH #8663: Before we read this key from the buffer, check that there's
// space for it. If we're calling Read without unidoce being set, then I
// believe we're also going to try and break this key event into one key
// for each OEM character. Problem is though, one unicode codepoint can
// be more than two chars long. So don't just use IsGlyphFullWidth,
// actually check with the codepoint how wide this key should be.
size_t sizeOfThisKey = 1;
const auto& keyToRead{ _storage.front() };
if (!unicode)
{
Expand All @@ -420,46 +427,25 @@ void InputBuffer::_ReadBuffer(_Out_ std::deque<std::unique_ptr<IInputEvent>>& ou
// convert from wchar to char
std::wstring wstr{ pKeyEvent->GetCharData() };
const auto str = ConvertToA(codepage, wstr);
const auto sizeOfThisKey{ str.size() };
sizeOfThisKey = str.size();
if (virtualReadCount + sizeOfThisKey > readCount)
{
break;
}
}
}
// TODO!: If we do this, then readers who come asking for 4 events might
// only get 3 back, under the implication that they know they need to
// expand the events themselves. Who are all the InputBuffer::Read
// callers? Are they all expanding (in the case of !unicode) in post?

if (performNormalRead)
{
readEvents.push_back(std::move(_storage.front()));
_storage.pop_front();
}

++virtualReadCount;
if (!unicode)
{
if (readEvents.back()->EventType() == InputEventType::KeyEvent)
{
const KeyEvent* const pKeyEvent = static_cast<const KeyEvent* const>(readEvents.back().get());

if (!unicode)
{
// convert from wchar to char
std::wstring wstr{ pKeyEvent->GetCharData() };
const auto str = ConvertToA(codepage, wstr);
if (str.size() > 1)
{
virtualReadCount += (str.size() - 1);
}
}
else
{
if (IsGlyphFullWidth(pKeyEvent->GetCharData()))
{
++virtualReadCount;
}
}
}
}
virtualReadCount += sizeOfThisKey;
}

// the amount of events that were actually read
Expand Down
4 changes: 4 additions & 0 deletions src/host/ut_host/InputBufferTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,10 @@ class InputBufferTests
resetWaitEvent,
false,
false);

// TODO! I broke this test. This test expects 4 events to get read back, regardless of the fact that one would get expanded by ConvertToA.
// This might be okay, the test probably shouldn't be calling the private method directly.

// the dbcs record should have counted for two elements in
// the array, making it so that we get less events read
VERIFY_ARE_EQUAL(eventsRead, recordInsertCount - 1);
Expand Down

1 comment on commit e687d17

@github-actions

This comment was marked as outdated.

Please sign in to comment.