winaccessibility/source/UAccCOM/AccTextBase.cxx | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-)
New commits: commit a1ad4744a17193c9627f802fc3746d69375ccf08 Author: Michael Weghorn <m.wegh...@posteo.de> AuthorDate: Fri Jun 14 10:57:58 2024 +0200 Commit: Michael Weghorn <m.wegh...@posteo.de> CommitDate: Sat Jun 15 00:40:59 2024 +0200 wina11y: Fix handling for special text offset -1 As described in the IAccessible2 spec [1], -1 can be used as a special text offset: > Using IA2_TEXT_OFFSET_LENGTH (-1) as an offset in any of the > IAccessibleText or IAccessibleEditableText methods is the same > as specifying the length of the string. Replace -1 by the text length *before* doing the check whether end offset is smaller than the start offset. Otherwise, trying to query the whole text of a Writer paragraph containing the text "hello" in NVDA's Python console would incorrectly trigger an error: >>> focus.IAccessibleTextObject.text(0,-1) Traceback (most recent call last): File "<console>", line 1, in <module> File "comtypes\__init__.pyc", line 856, in __call__ File "monkeyPatches _ctypes.COMError: (-2147467259, 'Unspecified error', (None, None, None, 0, None)) With this commit in place, it works as expected: >>> focus.IAccessibleTextObject.text(0,-1) 'hello' [1] https://accessibility.linuxfoundation.org/a11yspecs/ia2/docs/html/_general_info.html#_specialOffsets Change-Id: I489a42270a56178cc8ee0564eec3dc82e15969c4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168853 Reviewed-by: Michael Weghorn <m.wegh...@posteo.de> Tested-by: Jenkins (cherry picked from commit 0c7928dc10da2c8c5ce9910fe20cea439573f2ae) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168885 diff --git a/winaccessibility/source/UAccCOM/AccTextBase.cxx b/winaccessibility/source/UAccCOM/AccTextBase.cxx index a50cee9dd41c..857b52f2f53f 100644 --- a/winaccessibility/source/UAccCOM/AccTextBase.cxx +++ b/winaccessibility/source/UAccCOM/AccTextBase.cxx @@ -438,25 +438,13 @@ COM_DECLSPEC_NOTHROW STDMETHODIMP CAccTextBase::get_text(long startOffset, long if(!pRXText.is()) return E_FAIL; - if (endOffset < -1 || endOffset < startOffset ) - { - return E_FAIL; - } + if (endOffset == -1) + endOffset = pRXText->getCharacterCount(); - OUString ouStr; - if (endOffset == -1 ) - { - long nLen=0; - if(SUCCEEDED(get_characterCount(&nLen))) - { - ouStr = pRXText->getTextRange(0, nLen); - } - } - else - { - ouStr = pRXText->getTextRange(startOffset, endOffset); - } + if (endOffset < 0 || endOffset < startOffset) + return E_FAIL; + const OUString ouStr = pRXText->getTextRange(startOffset, endOffset); SysFreeString(*text); *text = SysAllocString(o3tl::toW(ouStr.getStr())); return S_OK;