tdf#148358 - Compare Non-ASCII variable names case-insensitive

Change-Id: I761eb27b16c92d58df1be8e6011fc9b94db2a59c
diff --git a/basic/qa/basic_coverage/test_non_ascii_names.bas b/basic/qa/basic_coverage/test_non_ascii_names.bas
index a9ef0f1..905f82e 100644
--- a/basic/qa/basic_coverage/test_non_ascii_names.bas
+++ b/basic/qa/basic_coverage/test_non_ascii_names.bas
@@ -7,6 +7,7 @@
'

Option Explicit
Option Compatible

Function doUnitTest as String
  [Prüfung]
@@ -17,10 +18,26 @@ Function [Функция]([😁])
  [Функция] = [😁] & " and some text"
End Function

Function TestNonAscii as Integer
    Dim Абв as Integer
    Абв = 10
    TestNonAscii = абв
End Function

Function TestNonAsciiNative as Integer
    Dim [Абв] as Integer
    [Абв] = 5
    TestNonAsciiNative = [абв]
End Function

Sub [Prüfung]
  On Error GoTo errorHandler

  TestUtil.AssertEqual([Функция]("Smiley"), "Smiley and some text", "[Функция](""Smiley"")")
  
  ' tdf#148358 - compare Non-ASCII variable names case-insensitive
  TestUtil.AssertEqual(TestNonAscii(), 10, "TestNonAscii()")
  TestUtil.AssertEqual(TestNonAsciiNative(), 5, "TestNonAsciiNative()")

  Exit Sub
errorHandler:
diff --git a/basic/qa/cppunit/test_vba.cxx b/basic/qa/cppunit/test_vba.cxx
index 68d9bbaf..d3f4017 100644
--- a/basic/qa/cppunit/test_vba.cxx
+++ b/basic/qa/cppunit/test_vba.cxx
@@ -136,6 +136,7 @@ void VBATest::testMiscVBAFunctions()
        "strreverse.vb",
        "switch.vb",
        "tdf147089_idiv.vb",
        "tdf148358_non_ascii_names.vb",
        "timeserial.vb",
        "timevalue.vb",
        "trim.vb",
diff --git a/basic/qa/vba_tests/tdf148358_non_ascii_names.vb b/basic/qa/vba_tests/tdf148358_non_ascii_names.vb
new file mode 100644
index 0000000..8e4bdab
--- /dev/null
+++ b/basic/qa/vba_tests/tdf148358_non_ascii_names.vb
@@ -0,0 +1,33 @@
'
' This file is part of the LibreOffice project.
'
' This Source Code Form is subject to the terms of the Mozilla Public
' License, v. 2.0. If a copy of the MPL was not distributed with this
' file, You can obtain one at http://mozilla.org/MPL/2.0/.
'

Option VBASupport 1
Option Explicit

Function doUnitTest as String
  TestUtil.TestInit
  verify_testNonAsciiNames
  doUnitTest = TestUtil.GetResult()
End Function

Function TestNonAscii as Integer
    Dim Абв as Integer
    Абв = 10
    TestNonAscii = абв
End Function

Sub verify_testNonAsciiNames
  On Error GoTo errorHandler
 
  ' tdf#148358 - compare Non-ASCII variable names case-insensitive
  TestUtil.AssertEqual(TestNonAscii(), 10, "TestNonAscii()")

  Exit Sub
errorHandler:
  TestUtil.ReportErrorHandler("verify_testNonAsciiNames", Err, Error$, Erl)
End Sub
diff --git a/basic/source/sbx/sbxarray.cxx b/basic/source/sbx/sbxarray.cxx
index d8f16f5..5f70345 100644
--- a/basic/source/sbx/sbxarray.cxx
+++ b/basic/source/sbx/sbxarray.cxx
@@ -277,6 +277,8 @@ SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )
        return nullptr;
    bool bExtSearch = IsSet( SbxFlagBits::ExtSearch );
    sal_uInt16 nHash = SbxVariable::MakeHashCode( rName );
    //const OUString aNameCI = SbxVariable::NameToCaseInsensitiveName(rName);
    const OUString aNameCI = SbxVariable::NameToCaseInsensitiveName(rName);
    for (auto& rEntry : mVarEntries)
    {
        if (!rEntry.mpVar.is() || !rEntry.mpVar->IsVisible())
@@ -284,9 +286,10 @@ SbxVariable* SbxArray::Find( const OUString& rName, SbxClassType t )

        // The very secure search works as well, if there is no hashcode!
        sal_uInt16 nVarHash = rEntry.mpVar->GetHashCode();
        // tdf#148358 - compare the names case-insensitive
        if ( (!nVarHash || nVarHash == nHash)
            && (t == SbxClassType::DontCare || rEntry.mpVar->GetClass() == t)
            && (rEntry.mpVar->GetName().equalsIgnoreAsciiCase(rName)))
            && (rEntry.mpVar->GetName(SbxNameType::CaseInsensitive) == aNameCI))
        {
            p = rEntry.mpVar.get();
            p->ResetFlag(SbxFlagBits::ExtFound);