basic/qa/cppunit/test_compiler_checks.cxx | 41 ++++++++++++++++++++++++++++++ basic/source/comp/scanner.cxx | 7 ++++- basic/source/inc/scanner.hxx | 1 3 files changed, 48 insertions(+), 1 deletion(-)
New commits: commit ed3d572b730d1873dd66fa2a31695248d506a335 Author: Andreas Heinisch <andreas.heini...@yahoo.de> AuthorDate: Fri Jun 3 09:41:05 2022 +0200 Commit: Xisco Fauli <xiscofa...@libreoffice.org> CommitDate: Mon Jun 6 17:08:15 2022 +0200 tdf#149402 - BASIC: Don't extend comment if line ends in a whitespace Change-Id: I8adf530e77a0e65329fa59ac2873b99f48befac4 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135336 Tested-by: Jenkins Reviewed-by: Andreas Heinisch <andreas.heini...@yahoo.de> (cherry picked from commit fbce18558a58cddf910b788a67c2f2d4d25d68e9) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135378 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> diff --git a/basic/qa/cppunit/test_compiler_checks.cxx b/basic/qa/cppunit/test_compiler_checks.cxx index e2882f3f694c..044977670e62 100644 --- a/basic/qa/cppunit/test_compiler_checks.cxx +++ b/basic/qa/cppunit/test_compiler_checks.cxx @@ -73,4 +73,45 @@ CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149157_vba) CPPUNIT_ASSERT(!aMacro.HasError()); } +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402) +{ + MacroSnippet aMacro("Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_compatible) +{ + MacroSnippet aMacro("Option Compatible\n" + "Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + aMacro.Compile(); + CPPUNIT_ASSERT(!aMacro.HasError()); +} + +CPPUNIT_TEST_FIXTURE(CppUnit::TestFixture, testTdf149402_vba) +{ + MacroSnippet aMacro("Option VBASupport 1\n" + "Function extentComment() As Integer\n" + " ' _ \n" + " If Not extentComment Then\n" + " extentComment = 1\n" + " Else\n" + " End If\n" + "End Function\n"); + 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/source/comp/scanner.cxx b/basic/source/comp/scanner.cxx index d391e7b6dff2..8c63dcd6643c 100644 --- a/basic/source/comp/scanner.cxx +++ b/basic/source/comp/scanner.cxx @@ -53,6 +53,7 @@ SbiScanner::SbiScanner(const OUString& rBuf, StarBASIC* p) , bVBASupportOn(false) , bPrevLineExtentsComment(false) , bClosingUnderscore(false) + , bLineEndsWithWhitespace(false) , bInStatement(false) { } @@ -186,6 +187,8 @@ bool SbiScanner::readLine() while(nBufPos < nEnd && BasicCharClass::isWhitespace(aBuf[nEnd - 1])) --nEnd; + // tdf#149402 - check if line ends with a whitespace + bLineEndsWithWhitespace = (n > nEnd); aLine = aBuf.copy(nBufPos, nEnd - nBufPos); // Fast-forward past the line ending @@ -663,7 +666,9 @@ PrevLineCommentLbl: bPrevLineExtentsComment = false; aSym = "REM"; sal_Int32 nLen = aLine.getLength() - nLineIdx; - if( bCompatible && aLine[nLineIdx + nLen - 1] == '_' && aLine[nLineIdx + nLen - 2] == ' ' ) + // tdf#149402 - don't extend comment if line ends in a whitespace (asicCharClass::isWhitespace) + if (bCompatible && !bLineEndsWithWhitespace && aLine[nLineIdx + nLen - 1] == '_' + && aLine[nLineIdx + nLen - 2] == ' ') bPrevLineExtentsComment = true; nCol2 = nCol2 + nLen; nLineIdx = -1; diff --git a/basic/source/inc/scanner.hxx b/basic/source/inc/scanner.hxx index 39dda9fa391c..cc3cbb5d7b41 100644 --- a/basic/source/inc/scanner.hxx +++ b/basic/source/inc/scanner.hxx @@ -62,6 +62,7 @@ protected: bool bVBASupportOn; // true: OPTION VBASupport 1 otherwise default False bool bPrevLineExtentsComment; // true: Previous line is comment and ends on "... _" bool bClosingUnderscore; // true: Closing underscore followed by end of line + bool bLineEndsWithWhitespace; // true: Line ends with whitespace (BasicCharClass::isWhitespace) bool bInStatement; void GenError( ErrCode );