sw/source/ui/vba/vbadocument.cxx | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-)
New commits: commit 609a1567d0e60ca11800df56059b97b6a61ad117 Author: Justin Luth <jl...@mail.com> AuthorDate: Mon Jun 26 20:14:17 2023 -0400 Commit: Justin Luth <jl...@mail.com> CommitDate: Tue Jun 27 04:06:26 2023 +0200 tdf#151548 ContentControls vba: allow search by float #2 I don't know how to figure out where the basic parsing is mishandling the double-specifier of "#", so just hack in a re-attempt to find a control with the name of an unfound index. This should be fine. If it really was specifying an index, then it won't get to this code. If the number is larger than the index and a control exists with that id, then it almost certainly was intended as a name. If by some chance it wasn't, then instead of the code failing, it will actually go ahead with the operation. Since in practical terms this won't happen, just go ahead and fix the likely case of a positive-number-as-a-name control not being found. Change-Id: I2a34184d86b99a50fdc6b806264f1d5e7794ad48 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153630 Tested-by: Jenkins Reviewed-by: Justin Luth <jl...@mail.com> diff --git a/sw/source/ui/vba/vbadocument.cxx b/sw/source/ui/vba/vbadocument.cxx index 4f20311879ad..c8985464501d 100644 --- a/sw/source/ui/vba/vbadocument.cxx +++ b/sw/source/ui/vba/vbadocument.cxx @@ -225,7 +225,24 @@ uno::Any SwVbaDocument::ContentControls(const uno::Any& index) uno::Reference<XCollection> xContentControls( new SwVbaContentControls(this, mxContext, mxTextDocument, "", "")); if (index.hasValue()) - return xContentControls->Item(index, uno::Any()); + { + try + { + return xContentControls->Item(index, uno::Any()); + } + catch (lang::IndexOutOfBoundsException&) + { + // Hack: Instead of an index, it might be a float that was mistakenly treated as a long, + // which can happen with any valid positive integer when specified as a double like + // ActiveDocument.ContentControls(1841581653#). + if (index.getValueTypeClass() == css::uno::TypeClass_LONG) + { + sal_Int32 nLong(0); + index >>= nLong; + return xContentControls->Item(uno::Any(static_cast<double>(nLong)), uno::Any()); + } + } + } return uno::Any(xContentControls); }