Issue with Edit Function changing ValidateRange

This forum can be browsed by the general public. Posting is limited to current SAPIEN license holders with active maintenance and does not offer a response time guarantee.
Forum rules
DO NOT POST LICENSE NUMBERS, ACTIVATION KEYS OR ANY OTHER LICENSING INFORMATION IN THIS FORUM.
Only the original author and our tech personnel can reply to a topic that is created in this forum. If you find a topic that relates to an issue you are having, please create a new topic and reference the other in your post.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 4 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
User avatar
jdainsworth
Posts: 25
Last visit: Thu Dec 14, 2023 9:10 am

Issue with Edit Function changing ValidateRange

Post by jdainsworth »

To help you better we need some information from you.

*** Please fill in the fields below. If you leave fields empty or specify 'latest' rather than the actual version your answer will be delayed as we will be forced to ask you for this information. ***

Product, version and build: Powershell Studio 2019, 5.6.167
32 or 64 bit version of product: 64-bit
Operating system: Windows 10
32 or 64 bit OS: 64-bit

*** Please add details and screenshots as needed below. ***

I have noticed an issue when executing "edit function", and powershell studio is modifying a ValidateRange.

If i have the following set:
function test-function {
PARAM
(
[ValidateRange(1,[int]::MaxValue)]
[int]$Count= 10
)

}

if you edit the function (you only need to open the menu, and click ok), it will change it to the following:
function test-function {
PARAM
(
[ValidateRange(1,1)]
[int]$Count= 10
)

}

which breaks the intention of the ValidateRange
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Issue with Edit Function changing ValidateRange

Post by mxtrinidad »

Thanks for reporting the issue. Our team will investigate and get back to you.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Issue with Edit Function changing ValidateRange

Post by mxtrinidad »

This is what's happening...

First, there's nothing wrong with the "Edit Function".

To properly use the "Edit Function", you need to go the "Parameters" popup window and in the "Misc" field change "MaxRange" value from "1" to "10".
EditFunction_01_2019-08-15_14-08-34.png
EditFunction_01_2019-08-15_14-08-34.png (195.59 KiB) Viewed 2121 times
After clicking "OK", then you get:

function test-function {
param
(
[ValidateRange(1, 10)]
[int]$Count = 10
)

#TODO: Place script here
}

But, this means that you don't need to assign the value "10" to the $Count variable.

function test-function {
param
(
[ValidateRange(1, 10)]
[int]$Count
)

#TODO: Place script here
}

So the "Edit Functions" will not interpret the .NET code: "[int]::MaxValue)" as instead it need an Integer value.

Hope this helps!
User avatar
jdainsworth
Posts: 25
Last visit: Thu Dec 14, 2023 9:10 am

Re: Issue with Edit Function changing ValidateRange

Post by jdainsworth »

I don't want the end range to be 10, I want it to be [int]::MaxValue. However that is beside the point. I created a range validation by hand, opened the edit window, and it altered a manually created range validation, and specifically changed it to a code breaking value.

I would consider this to be a fairly major issue. Powershell Studio should not alter a RangeValidation (or any other properties of a parameter). If it is unable to parse the input, or it is going to make a breaking change because it doesn't understand the code, it should notify the user and not make any changes.
User avatar
mxtrinidad
Posts: 399
Last visit: Tue May 16, 2023 6:52 am

Re: Issue with Edit Function changing ValidateRange

Post by mxtrinidad »

Valid Point! If is a valid line then it shouldn't make the change.
I would recommend to please submit "Feature Request" to: https://www.sapien.com/requests

We appreciate your feedback!
This topic is 4 years and 7 months old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.