Bug 152351 (Hagen) - SF_Dictionary ReplaceItem does not accept array as value
Summary: SF_Dictionary ReplaceItem does not accept array as value
Status: RESOLVED FIXED
Alias: Hagen
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.4.2.3 release
Hardware: All Windows (All)
: medium normal
Assignee: Jean-Pierre Ledure
URL:
Whiteboard: target:7.6.0 target:7.4.4 target:7.5....
Keywords:
Depends on:
Blocks:
 
Reported: 2022-12-02 12:47 UTC by mail
Modified: 2022-12-14 08:17 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 mail 2022-12-02 12:47:21 UTC
Description:
SF_Dictionary ReplaceItem does not accept array as input value.
If you do then an exception will be thrown.

In the code the switch for input value to check if is array is missing like we see it in "Add"

Add:
		If IsArray(Item) Then
			If Not SF_Utils._ValidateArray(Item, "Item") Then GoTo Catch
		Else
			If Not SF_Utils._Validate(Item, "Item") Then GoTo Catch
		End If
ReplaceItem:
		If Not SF_Utils._Validate(Value, "Value") Then GoTo Catch


Where ADD-"Item" = ReplaceItem-"Value"

Steps to Reproduce:
1. Dim myDict as Variant
2. myDict = CreateScriptService("Dictionary")
3. myDict.Add("key", Array())
4. myDict.ReplaceItem("key", Array())

Actual Results:
Exception with Text:
Library :   ScriptForge
Service :   Dictionary
Method :    ReplaceItem
Arguments: Key, Value


A serious error has been detected in your code on argument : « Value ».

    Validation rules :

The actual value of « Value » is : '[ARRAY] ()'


THE EXECUTION IS CANCELLED.

Do you want to receive more information about the 'ReplaceItem' method ?

Expected Results:
No Errors


Reproducible: Always


User Profile Reset: No

Additional Info:
ReplaceItem
Replaces an existing item value based on its key. Returns True if successful.

Syntax:
dict.ReplaceItem(key: str, value: any): bool

Parameters:
key: String value representing the key whose value will be replaced. Not case-sensitive. If the key does not exist in the dictionary, an UNKNOWNKEYERROR error is raised.

value: The new value of the item referred to with the key parameter.

Example:
myDict.Add("a", 1)
MsgBox(myDict.Item("a")) ' 1
myDict.ReplaceItem("a", 100)
MsgBox(myDict.Item("a")) ' 100
Comment 1 Rafael Lima 2022-12-12 20:50:31 UTC
I can confirm the issue using the latest master.

@JPL what do you think? Can this be easily fixed?
Comment 2 Jean-Pierre Ledure 2022-12-13 10:33:03 UTC
I confirm the bug on master as well.

mail@hagen-meyer.de suggests a fix in the description of the error.

I implemented the suggestion as it was exactly what had to be done.

See https://gerrit.libreoffice.org/c/core/+/144041

The patch will be pushed to master as soon as Jenkins agrees the change.

JPL
Comment 3 Commit Notification 2022-12-13 14:40:56 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/57e2245abf50cbd207d5c9c57ed67c055f8afcd6

SF_Dictionary: tdf#152351 Fix ReplaceItem does not accept array as value

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 2022-12-13 16:42:26 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-7-4":

https://git.libreoffice.org/core/commit/50fde068eb702354e4b603231577c807b5e07d1a

SF_Dictionary: tdf#152351 Fix ReplaceItem does not accept array as value

It will be available in 7.4.4.

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 Commit Notification 2022-12-14 08:16:44 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-7-5":

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

SF_Dictionary: tdf#152351 Fix ReplaceItem does not accept array as value

It will be available in 7.5.0.0.beta2.

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.