Bug 159862 - Calc Macro set SearchWildcard to False changes SearchRegularExpression value.
Summary: Calc Macro set SearchWildcard to False changes SearchRegularExpression value.
Status: VERIFIED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
5.2.0.4 release
Hardware: x86-64 (AMD64) All
: medium normal
Assignee: Julien Nabet
URL:
Whiteboard: target:24.8.0 target:24.2.2
Keywords:
Depends on:
Blocks:
 
Reported: 2024-02-23 23:13 UTC by Don
Modified: 2024-03-07 17:27 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 Don 2024-02-23 23:13:42 UTC
Description:
In Calc, while using a Macro to modify the settings of a Search Descriptor, setting the value of .SearchWildcard to false, even though .SearchWildcard is already set to False, changes the value of .SearchRegularExpression to false again if it was set tot true.

Steps to Reproduce:
1. Create a SearchDescriptor
2. Set .SearchRegularExpression to true
3. Set .SearchWildcard to false
4. Check the value of .SearchRegularExpression again. it will now be false.

Actual Results:
Setting .SearchWildcard to False, changes .SearchRegularExpression to False also.

Expected Results:
If .SearchWildcard is set to False, .SearchRegularExpression should not be altered.


Reproducible: Always


User Profile Reset: Yes

Additional Info:
The below macro will demonstrate the error.

Sub main
  Dim oDescriptor  'The search descriptor

  oDescriptor = ThisComponent.CurrentController.getActiveSheet().createSearchDescriptor()

oDescriptor.SearchRegularExpression = true 
msgbox(oDescriptor.SearchRegularExpression)

oDescriptor.SearchWildcard = fasle
msgbox(oDescriptor.SearchRegularExpression)

End Sub

Version: 7.3.4.2 (x64) / LibreOffice Community
Build ID: 728fec16bd5f605073805c3c9e7c4212a0120dc5
CPU threads: 2; OS: Windows 6.1 Service Pack 1 Build 7601; UI render: Skia/Raster; VCL: win
Locale: en-US (en_US); UI: en-US
Calc: CL
Comment 1 Julien Nabet 2024-02-24 08:42:51 UTC
Indeed!
On pc Debian x86-64 with master sources updated today, I could reproduce this.

Here's the debug:
1) when calling oDescriptor.SearchRegularExpression = true, it gets there:
    348 void SvxSearchItem::SetRegExp( bool bVal )
    349 {
    350     if ( bVal )
    351     {
    352         m_aSearchOpt.AlgorithmType2 = SearchAlgorithms2::REGEXP; <==HERE
    353     }
    354     else if ( SearchAlgorithms2::REGEXP == m_aSearchOpt.AlgorithmType2 )
    355     {
    356         m_aSearchOpt.AlgorithmType2 = SearchAlgorithms2::ABSOLUTE;
    357     }
    358 }

#0  SvxSearchItem::SetRegExp(bool) (this=0x55feb38452e0, bVal=true) at svl/source/items/srchitem.cxx:352
#1  0x00007fee5382583d in ScCellSearchObj::setPropertyValue(rtl::OUString const&, com::sun::star::uno::Any const&)
    (this=0x55feb370b1f0, aPropertyName="SearchRegularExpression", aValue=uno::Any("boolean": 1 '\001')) at sc/source/ui/unoobj/srchuno.cxx:136
=> OK


2) when calling msgbox(oDescriptor.SearchRegularExpression), it gets there:
    243 bool SvxSearchItem::GetRegExp() const
    244 {
    245     return m_aSearchOpt.AlgorithmType2 == css::util::SearchAlgorithms2::REGEXP ;
    246 }

#0  SvxSearchItem::GetRegExp() const (this=0x55feb38452e0) at include/svl/srchitem.hxx:245
#1  0x00007fee538260a6 in ScCellSearchObj::getPropertyValue(rtl::OUString const&) (this=0x55feb370b1f0, aPropertyName="SearchRegularExpression") at sc/source/ui/unoobj/srchuno.cxx:159

so here it returns true as expected.
=> OK

3) when calling oDescriptor.SearchWildcard = false, it gets there:
    361 void SvxSearchItem::SetWildcard( bool bVal )
    362 {
    363     if ( bVal )
    364     {
    365         m_aSearchOpt.AlgorithmType2 = SearchAlgorithms2::WILDCARD;
    366     }
    367     else if ( SearchAlgorithms2::REGEXP == m_aSearchOpt.AlgorithmType2 )
    368     {
    369         m_aSearchOpt.AlgorithmType2 = SearchAlgorithms2::ABSOLUTE;//HERE
    370     }
    371 }


So when calling msgbox(oDescriptor.SearchRegularExpression) the second time, it returns false since now m_aSearchOpt.AlgorithmType2 = SearchAlgorithms2::ABSOLUTE and not css::util::SearchAlgorithms2::REGEXP
=> KO

I suppose line 367 is a wrong copy-paste, it should be:
else if ( SearchAlgorithms2::WILDCARD == m_aSearchOpt.AlgorithmType2 )

It's been like this since 3a0abd3019ec3ca29b8f1378cdb32ebf741e6306
add SvxSearchItem::GetWildcard() SetWildcard()
in 2016

Patch on gerrit here:
https://gerrit.libreoffice.org/c/core/+/163876
Comment 2 Commit Notification 2024-02-24 10:24:15 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "master":

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

tdf#159862: set SearchWildcard to false changes SearchRegularExpression value

It will be available in 24.8.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 3 Julien Nabet 2024-02-24 10:25:57 UTC
Patch for 24.2 branch waiting for review here:
https://gerrit.libreoffice.org/c/core/+/163836
Comment 4 Commit Notification 2024-02-26 16:57:06 UTC
Julien Nabet committed a patch related to this issue.
It has been pushed to "libreoffice-24-2":

https://git.libreoffice.org/core/commit/0e803a23b8a1c4c66cdd3cef00252867ba9a1193

tdf#159862: set SearchWildcard to false changes SearchRegularExpression value

It will be available in 24.2.2.

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 5 Don 2024-03-07 17:23:08 UTC
I can confirm the bug is fixed in the daily build. Thank you Julien Nabet.
Comment 6 Julien Nabet 2024-03-07 17:27:55 UTC
Thank you for the feedback Don!
Let's put this one to VERIFIED then.