-
-
Notifications
You must be signed in to change notification settings - Fork 70
Description
Hi, I've stumbled onto a very strange and potentially very dangerous issue with SPE and combo buttons, where it basically seems that a "sub" button script may use the wrong context item when running the script. Obviously depending on the script this could have very bad consequences so I hope you'll be able to reproduce it and figure out what's going on.
Expected Behavior
Scripts added as combo buttons in the ribbon should correctly resolve the current context item when using Get-Item . regardless of whether it is the "main" button or a "sub" button.
Actual Behavior
A combo "sub" button using Get-Item . incorrectly resolves the context item until the "main" button has been clicked. If a "sub" button is clicked before the "main" button has been clicked, the item resolved is incorrect.
Steps to Reproduce the Problem
- Create a new script and store it under Script Library/something/Content Editor/Ribbon/something/something and name it Combo$something (just following the instructions from https://doc.sitecorepowershell.com/modules/integration-points/content-editor#ribbon)
- Create another new script as sub-item to the Combo$something
- Set the script body of both scripts to the following:
$item = Get-Item .
Show-Alert -Title $item.Name
Close-Window
- Rebuild integration points
- Recycle the app pool
- Select the "sitecore" item in the content editor and click the sub button directly
The expected result is that the alert displays "sitecore" but the actual result is that the alert displays "inetsrv" followed by an error. It doesn't matter which context item is selected. As soon as the "main" button is clicked (which will correctly display the name of the context item), the "sub" button will behave correctly until another context item is selected in the content editor. At that point, the "sub" button will display the name of the last "main" button clicked context item. For instance:
- Select the "sitecore" item and click the "main" script button (alert displays "sitecore")
- Click the "sub" button (also correctly displays "sitecore")
- Select the "content" item in the content editor and click the "sub" button (alert will incorrectly display "sitecore" instead of "content")
Super weird. It's like the item resolving part of the "sub" button script is somehow cached, and the only way to clear it is to recycle the app pool. Clearing all Sitecore caches doesn't make a difference.
Tested with:
Sitecore PowerShell Extensions 6.2.0.34182
Clean Sitecore 9.3
Windows PowerShell 5.1
-
Tested issue with clean install of Sitecore and the latest available version of SPE.
-
Asked questions on the Sitecore Slack Chat channel.
-
Reviewed questions and answers on the Sitecore Stack Exchange.