sc/qa/extras/macros-test.cxx | 30 ++++++++++++++++++++++++++++++ sc/qa/extras/testdocuments/tdf143582.ods |binary scripting/source/basprov/basscript.cxx | 2 ++ 3 files changed, 32 insertions(+)
New commits: commit cb97358ab845f13f1c57b410e59126f20652d552 Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Mon Aug 2 19:48:35 2021 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Aug 9 17:36:57 2021 +0200 tdf#143582 - Clear return value of the method before calling it Otherwise the function keeps a copy of its return value, which may be used in an upcoming call. Change-Id: I4977c39e1ce48cfd5ab067a4df4783f10505a9ae Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119905 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120197 diff --git a/sc/qa/extras/macros-test.cxx b/sc/qa/extras/macros-test.cxx index fae1e4f71027..68d43e1ce19d 100644 --- a/sc/qa/extras/macros-test.cxx +++ b/sc/qa/extras/macros-test.cxx @@ -59,6 +59,7 @@ public: void testTdf138646(); void testTdf105558(); void testTdf90278(); + void testTdf143582(); CPPUNIT_TEST_SUITE(ScMacrosTest); CPPUNIT_TEST(testStarBasic); @@ -84,6 +85,7 @@ public: CPPUNIT_TEST(testTdf138646); CPPUNIT_TEST(testTdf105558); CPPUNIT_TEST(testTdf90278); + CPPUNIT_TEST(testTdf143582); CPPUNIT_TEST_SUITE_END(); }; @@ -950,6 +952,34 @@ void ScMacrosTest::testTdf133889() xCloseable->close(true); } +void ScMacrosTest::testTdf143582() +{ + OUString aFileName; + createFileURL(u"tdf143582.ods", aFileName); + auto xComponent = loadFromDesktop(aFileName, "com.sun.star.sheet.SpreadsheetDocument"); + + css::uno::Any aRet; + css::uno::Sequence<css::uno::Any> aParams; + css::uno::Sequence<css::uno::Any> aOutParam; + css::uno::Sequence<sal_Int16> aOutParamIndex; + + SfxObjectShell::CallXScript( + xComponent, + "vnd.sun.Star.script:Standard.Module1.TestScriptInvoke?language=Basic&location=document", + aParams, aRet, aOutParamIndex, aOutParam); + + OUString aReturnValue; + aRet >>= aReturnValue; + + // Without the fix in place, this test would have failed with + // - Expected: Test + // - Actual : TeTest + CPPUNIT_ASSERT_EQUAL(OUString("Test"), aReturnValue); + + css::uno::Reference<css::util::XCloseable> xCloseable(xComponent, css::uno::UNO_QUERY_THROW); + xCloseable->close(true); +} + void ScMacrosTest::testTdf138646() { OUString aFileName; diff --git a/sc/qa/extras/testdocuments/tdf143582.ods b/sc/qa/extras/testdocuments/tdf143582.ods new file mode 100644 index 000000000000..05f4f07cea2c Binary files /dev/null and b/sc/qa/extras/testdocuments/tdf143582.ods differ diff --git a/scripting/source/basprov/basscript.cxx b/scripting/source/basprov/basscript.cxx index a22cd82f343e..6a9a8d1d8b7b 100644 --- a/scripting/source/basprov/basscript.cxx +++ b/scripting/source/basprov/basscript.cxx @@ -244,6 +244,8 @@ namespace basprov if ( m_documentBasicManager && m_xDocumentScriptContext.is() ) aOldThisComponent = m_documentBasicManager->SetGlobalUNOConstant( "ThisComponent", makeAny( m_xDocumentScriptContext ) ); + // tdf#143582 - clear return value of the method before calling it + m_xMethod->Clear(); if ( m_caller.hasElements() && m_caller[ 0 ].hasValue() ) { SbxVariableRef xCallerVar = new SbxVariable( SbxVARIANT );