QWindowsUiaProvider: Check for empty narrator string

In case of password fields, the narrator may return a emptry QString,
this was not checked when using operator[]. This patch explicitly checks
for an empty string returned by the QWindowsUiaProvider.

Fixes: QTBUG-126822
Change-Id: I9e2c3cfc5fb6dc9a7dd7badff4280f60b24c0a4b
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 1ee349bf9d249ea45bc01c45473db44b9d335eed)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Wladimir Leuschner 2024-07-02 12:35:00 +02:00 committed by Qt Cherry-pick Bot
parent b64031a6d1
commit 33c7170fcb

View File

@ -111,7 +111,7 @@ HRESULT QWindowsUiaTextRangeProvider::ExpandToEnclosingUnit(TextUnit unit)
const int start = m_startOffset >= 0 && m_startOffset < len
? m_startOffset : len - 1;
for (int t = start; t >= 0; --t) {
if (!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) {
if (!text.isEmpty() && !isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) {
m_startOffset = t;
break;
}
@ -412,7 +412,7 @@ HRESULT QWindowsUiaTextRangeProvider::MoveEndpointByUnit(TextPatternRangeEndpoin
if (endpoint == TextPatternRangeEndpoint_Start) {
if (count > 0) {
for (int t = m_startOffset; (t < len - 1) && (moved < count); ++t) {
if (isTextUnitSeparator(unit, text[t]) && !isTextUnitSeparator(unit, text[t + 1])) {
if (!text.isEmpty() && isTextUnitSeparator(unit, text[t]) && !isTextUnitSeparator(unit, text[t + 1])) {
m_startOffset = t + 1;
++moved;
}
@ -422,7 +422,7 @@ HRESULT QWindowsUiaTextRangeProvider::MoveEndpointByUnit(TextPatternRangeEndpoin
const int start = m_startOffset >= 0 && m_startOffset <= len
? m_startOffset : len;
for (int t = start - 1; (t >= 0) && (moved > count); --t) {
if (!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) {
if (!text.isEmpty() &&!isTextUnitSeparator(unit, text[t]) && ((t == 0) || isTextUnitSeparator(unit, text[t - 1]))) {
m_startOffset = t;
--moved;
}