Revert "Bug 1968267: Ignore 0x0 0xa combination at end of clipboard text r=win-reviewers,gstoll a=RyanVM" as part of reverting Bug 1966443

This reverts commit 140ce197d1.
This commit is contained in:
DonalMe
2025-06-12 10:12:11 -04:00
committed by dmeehan@mozilla.com
parent 4c02d92b62
commit 62baff5750

View File

@@ -710,28 +710,17 @@ HRESULT nsClipboard::FillSTGMedium(IDataObject* aDataObject, UINT aFormat,
// since Windows also appears to add null termination. See GetGlobalData.
template <typename CharType>
static nsresult GetCharDataFromGlobalData(STGMEDIUM& aStm, CharType** aData,
uint32_t* aByteLen) {
uint32_t* aLen) {
uint32_t nBytes = 0;
MOZ_TRY(nsClipboard::GetGlobalData(aStm.hGlobal,
reinterpret_cast<void**>(aData), &nBytes));
auto nChars = nBytes / sizeof(CharType);
if (nChars < 1) {
*aByteLen = 0;
*aLen = 0;
return NS_OK;
}
const CharType* data = *aData;
if (nChars > 1 && data[nChars - 2] == CharType(0x00) &&
data[nChars - 1] == CharType(0x0a)) {
// The char array ends in the nonsense combination null + LF. Remove both.
// Word sometimes does this.
nChars -= 2;
} else if (data[nChars - 1] == CharType(0)) {
// Remove null termination.
nChars -= 1;
}
*aByteLen = nChars * sizeof(CharType);
bool hasNullTerminator = (*aData)[nChars - 1] == CharType(0);
*aLen = hasNullTerminator ? nBytes - sizeof(CharType) : nBytes;
return NS_OK;
}