From 48f0363fe07d2d56b1e4d597abcd7db26e15dd80 Mon Sep 17 00:00:00 2001 From: Neil Date: Thu, 11 Jun 2020 16:22:59 +1000 Subject: Fix bug on Win32 where calling WM_GETTEXT for more text than in document could return less text than in document. --- doc/ScintillaHistory.html | 4 ++++ test/win32Tests.py | 13 +++++++++++++ win32/ScintillaWin.cxx | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index f27c4c1cb..c6d5b0539 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -586,6 +586,10 @@ Fix printing on Windows to use correct text size. Bug #2185. +
  • + Fix bug on Win32 where calling WM_GETTEXT for more text than in document could return + less text than in document. +
  • Release 4.4.3 diff --git a/test/win32Tests.py b/test/win32Tests.py index 6032e8955..d47ed66db 100644 --- a/test/win32Tests.py +++ b/test/win32Tests.py @@ -130,6 +130,19 @@ class TestWins(unittest.TestCase): self.assertEquals(lenData, 2) self.assertEquals(data.value, "ab") + def testGetTextLongNonASCII(self): + # With 1 multibyte character in document ask for 4 and ensure 1 character + # returned correctly. + self.ed.SetCodePage(65001) + t = "å" + tu8 = t.encode("UTF-8") + self.SetText(tu8) + data = ctypes.create_unicode_buffer(100) + lenData = self.GetText(4, data) + self.assertEquals(self.ed.GetStatus(), 0) + self.assertEquals(lenData, 1) + self.assertEquals(data.value, t) + def testGetTextShort(self): self.assertEquals(self.ed.GetStatus(), 0) self.SetText(b"ab") diff --git a/win32/ScintillaWin.cxx b/win32/ScintillaWin.cxx index 5d0020d30..a0d1c024b 100644 --- a/win32/ScintillaWin.cxx +++ b/win32/ScintillaWin.cxx @@ -1342,7 +1342,7 @@ sptr_t ScintillaWin::GetText(uptr_t wParam, sptr_t lParam) { Sci::Position sizeRequestedRange = pdoc->GetRelativePositionUTF16(0, lengthWanted); if (sizeRequestedRange < 0) { // Requested more text than there is in the document. - sizeRequestedRange = pdoc->CountUTF16(0, pdoc->Length()); + sizeRequestedRange = pdoc->Length(); } std::string docBytes(sizeRequestedRange, '\0'); pdoc->GetCharRange(&docBytes[0], 0, sizeRequestedRange); -- cgit v1.2.3