Page 1 of 1

Issue with Edit Function changing ValidateRange

Posted: Thu Aug 15, 2019 10:35 am
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

Re: Issue with Edit Function changing ValidateRange

Posted: Thu Aug 15, 2019 10:47 am
by mxtrinidad
Thanks for reporting the issue. Our team will investigate and get back to you.

Re: Issue with Edit Function changing ValidateRange

Posted: Thu Aug 15, 2019 11:16 am
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 717 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!

Re: Issue with Edit Function changing ValidateRange

Posted: Thu Aug 15, 2019 3:13 pm
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.

Re: Issue with Edit Function changing ValidateRange

Posted: Thu Aug 15, 2019 4:09 pm
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!