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 SUBSCRIPTION NUMBERS, LICENSE 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.
User avatar
jdainsworth
Posts: 13
Joined: Mon May 23, 2016 8:48 am

Issue with Edit Function changing ValidateRange

Post by jdainsworth » Thu Aug 15, 2019 10:35 am

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
Site Admin
Posts: 354
Joined: Sun Mar 03, 2013 12:42 pm

Re: Issue with Edit Function changing ValidateRange

Post by mxtrinidad » Thu Aug 15, 2019 10:47 am

Thanks for reporting the issue. Our team will investigate and get back to you.

User avatar
mxtrinidad
Site Admin
Posts: 354
Joined: Sun Mar 03, 2013 12:42 pm

Re: Issue with Edit Function changing ValidateRange

Post by mxtrinidad » Thu Aug 15, 2019 11:16 am

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 686 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: 13
Joined: Mon May 23, 2016 8:48 am

Re: Issue with Edit Function changing ValidateRange

Post by jdainsworth » Thu Aug 15, 2019 3:13 pm

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
Site Admin
Posts: 354
Joined: Sun Mar 03, 2013 12:42 pm

Re: Issue with Edit Function changing ValidateRange

Post by mxtrinidad » Thu Aug 15, 2019 4:09 pm

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!