basic/qa/cppunit/test_compiler_checks.cxx |   55 ++++++++++++++++++++++++++++++
 basic/qa/vba_tests/datevalue.vb           |    2 -
 basic/source/comp/parser.cxx              |    4 +-
 3 files changed, 58 insertions(+), 3 deletions(-)

New commits:
commit 047c84f431064d6bf5eeff536e6f554d4e63aac3
Author:     Alexandru Diaconu <[email protected]>
AuthorDate: Sun May 11 17:14:05 2025 +0300
Commit:     Mike Kaganski <[email protected]>
CommitDate: Mon May 12 16:05:27 2025 +0200

    tdf#162983 Restrict closure of Function and Sub to only End Function and 
Sub.
    
    Change-Id: Ib08b5961e61d7a151fa7c67666b0f5e31a7828b1
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/185185
    Tested-by: Jenkins
    Reviewed-by: Mike Kaganski <[email protected]>

diff --git a/basic/qa/cppunit/test_compiler_checks.cxx 
b/basic/qa/cppunit/test_compiler_checks.cxx
index 06586aaa3382..8562c11e6501 100644
--- a/basic/qa/cppunit/test_compiler_checks.cxx
+++ b/basic/qa/cppunit/test_compiler_checks.cxx
@@ -167,4 +167,59 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, 
testTdf93727_const)
     aMacro.Compile();
     CPPUNIT_ASSERT_MESSAGE("#Const directive causes compile error", 
!aMacro.HasError());
 }
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, 
testTdf162983_property_get_end_function)
+{
+    MacroSnippet aMacro(u"Option VBASupport 1
"
+                        "Property Get doUnitTest
"
+                        "End Function
"_ustr);
+    aMacro.Compile();
+    CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf162983_property_get_end_sub)
+{
+    MacroSnippet aMacro(u"Option VBASupport 1
"
+                        "Property Get doUnitTest
"
+                        "End Sub
"_ustr);
+    aMacro.Compile();
+    CPPUNIT_ASSERT(!aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf162983_sub_end_function)
+{
+    MacroSnippet aMacro(u"Option VBASupport 1
"
+                        "Sub doUnitTest
"
+                        "End Function
"_ustr);
+    aMacro.Compile();
+    CPPUNIT_ASSERT(aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf162983_sub_end_property)
+{
+    MacroSnippet aMacro(u"Option VBASupport 1
"
+                        "Sub doUnitTest
"
+                        "End Property
"_ustr);
+    aMacro.Compile();
+    CPPUNIT_ASSERT(aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf162983_function_end_sub)
+{
+    MacroSnippet aMacro(u"Option VBASupport 1
"
+                        "Function doUnitTest
"
+                        "End Sub
"_ustr);
+    aMacro.Compile();
+    CPPUNIT_ASSERT(aMacro.HasError());
+}
+
+CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf162983_function_end_property)
+{
+    MacroSnippet aMacro(u"Option VBASupport 1
"
+                        "Function doUnitTest
"
+                        "End Property
"_ustr);
+    aMacro.Compile();
+    CPPUNIT_ASSERT(aMacro.HasError());
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s 
cinkeys+=0=break: */
diff --git a/basic/qa/vba_tests/datevalue.vb b/basic/qa/vba_tests/datevalue.vb
index e433eba46149..2996da6f436f 100644
--- a/basic/qa/vba_tests/datevalue.vb
+++ b/basic/qa/vba_tests/datevalue.vb
@@ -24,4 +24,4 @@ Function verify_testDateValue() as String
     Exit Function
 errorHandler:
     TestUtil.ReportErrorHandler("verify_testFix", Err, Error$, Erl)
-End Sub
+End Function
diff --git a/basic/source/comp/parser.cxx b/basic/source/comp/parser.cxx
index 73896f616df3..df1fe3a15140 100644
--- a/basic/source/comp/parser.cxx
+++ b/basic/source/comp/parser.cxx
@@ -362,8 +362,8 @@ bool SbiParser::Parse()
     // end of parsing?
     if( eCurTok == eEndTok ||
         ( bVBASupportOn &&      // #i109075
-          (eCurTok == ENDFUNC || eCurTok == ENDPROPERTY || eCurTok == ENDSUB) 
&&
-          (eEndTok == ENDFUNC || eEndTok == ENDPROPERTY || eEndTok == ENDSUB) 
) )
+          eEndTok == ENDPROPERTY &&
+          ( eCurTok == ENDFUNC || eCurTok == ENDSUB) ) )
     {
         Next();
         if( eCurTok != NIL )

Reply via email to