Bug 152690 - Operator Like handles "!" in character set wrong, when "!" is not the first in the set
Summary: Operator Like handles "!" in character set wrong, when "!" is not the first i...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: All All
: medium normal
Assignee: Baole Fang
URL:
Whiteboard: target:7.6.0
Keywords: difficultyBeginner, easyHack, skillCpp
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2022-12-26 18:44 UTC by Mike Kaganski
Modified: 2023-03-18 18:08 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-12-26 18:44:58 UTC
LibreOffice supports Like operator [1], when using Option Compatible or Option VBASupport.

Consider this code:

Sub TestLike()
  MsgBox "!" Like "[.!?]"
  MsgBox "^" Like "[.!?]"
End Sub

In MS VBA, it produces "True" first, and then "False".
In LibreOffice, it produces "False" first, and then "True".

This is because character "!" should mean negation, only when it's the first character in the group; in other positions, it matches itself.

Code pointer: function VBALikeToRegexp in basic/source/runtime/runtime.cxx, which should only check for "!" immediately after "[", and not in other positions.

[1] https://learn.microsoft.com/en-us/office/vba/language/reference/user-interface-help/like-operator
Comment 1 Stéphane Guillou (stragu) 2022-12-28 23:12:00 UTC
Reproduced:

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 29c2bba1f3ef216d226c97197185066880fc1ab5
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: threaded
Comment 2 Baole Fang 2023-03-12 01:32:48 UTC
Also reproduced:

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: f5c466502a302b8e56486119e5e318fb02b479fe
CPU threads: 12; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: CL threaded

I'm new to libre and want to join the community, so I'd like to work on this issue.
Comment 3 Commit Notification 2023-03-16 21:14:36 UTC
Baole Fang committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/e12fff12b66561bc46a0e22f58919efa443e7e17

tdf#152690: Fix "!" behavior when it is not the first in a group

It will be available in 7.6.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.
Comment 4 Commit Notification 2023-03-17 04:47:09 UTC
Baole Fang committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/d34a3c92eb68b7f0b2cef698639a2853e19a898f

tdf#152690: Refactor fix

It will be available in 7.6.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.