Bug 148358 - Non-ASCII names are not case-insensitive
Summary: Non-ASCII names are not case-insensitive
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Andreas Heinisch
URL:
Whiteboard: target:7.4.0
Keywords:
Depends on:
Blocks:
 
Reported: 2022-04-04 10:44 UTC by Mike Kaganski
Modified: 2022-05-07 14:13 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Kaganski 2022-04-04 10:44:16 UTC
Consider the code:

  Option Compatible

  Sub TestNonAscii
    Абв = 10
    MsgBox абв
  End Sub

The code uses a Cyrillic characters for the variable name "Абв", and it uses the same name with first character lowercase in the next MsgBox statement. It must output "10", but instead, it shows empty dialog.

The problem is, the non-ASCII characters are not treated case-insensisively; in the code, there are "equalsIgnoreAsciiCase" calls on the result of SbxVariable::GetName left and right.

Commit de81c2545aec06a1b269218b7d00656e97d8b66c introduced a cached transliterated case-insensitive name value, obtained using SbxVariable::GetName with SbxNameType::CaseInsensitive. So instead of those equalsIgnoreAsciiCase, in compatibility mode we should compare for equality, using the transliterated case-insensitive value.
Comment 1 Mike Kaganski 2022-04-20 06:46:50 UTC
The same is true for native non-ASCII names, using [name] syntax, that doesn't require 'Option Compatible':

  Sub TestNonAsciiNative
    [Абв] = 5
    MsgBox [абв]
  End Sub
Comment 2 Andreas Heinisch 2022-05-02 19:22:27 UTC
Confirmed in:
Version: 7.4.0.0.alpha0+ (x64) / LibreOffice Community
Build ID: a58701650c2dd7ad8514752d571aa2569690fe37
CPU threads: 6; OS: Windows 10.0 Build 19044; UI render: Skia/Vulkan; VCL: win
Locale: de-DE (de_DE); UI: en-US
Calc: CL
Comment 3 Andreas Heinisch 2022-05-02 19:37:01 UTC
I have a prototype for this bug, but the naming conventions of the parser and the runtime confuses me.

The parser uses bCompatible and bVBASupportOn [1], whereas the runtime just uses  bCompatibility for the VBA runtime compatibility mode [2]. So the runtime has no information about Option Compatible to check in the comparision of the variable names [3]. So, should we rename the function in the runtime in order to get rid of that confusion? I'm not sure if it interferes in the image making process.

[1] https://opengrok.libreoffice.org/xref/core/basic/source/inc/scanner.hxx?r=67c15910#61
[2] https://opengrok.libreoffice.org/xref/core/basic/source/inc/runtime.hxx?r=d1207a5f#179
[3] https://opengrok.libreoffice.org/xref/core/basic/source/sbx/sbxarray.cxx?r=8024118d#289
Comment 4 Mike Kaganski 2022-05-03 06:03:24 UTC
(In reply to Andreas Heinisch from comment #3)

Given comment 1, I don't think that this bug needs any special handling wrt compatibility. The problem is comparison; and in all modes, we need to drop equalsIgnoreAsciiCase in favor of

>    aNameCI = SbGlobal::GetTransliteration().transliterate(rName, 0, rName.getLength());
>    ....
>        && (rEntry.mpVar->GetName(SbxNameType::CaseInsensitive) == rNameCI))

or the like.
Comment 5 Andreas Heinisch 2022-05-03 06:34:50 UTC
Ah ok, I thought this should happen only in with Option Compatible.
Comment 6 Commit Notification 2022-05-07 14:01:51 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/90d33f5945336fa46b7c02f425100af794768b15

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

It will be available in 7.4.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.