Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handles + character in supported equality and function operators in filter expressions #2999

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

timayabi2020
Copy link
Contributor



Fixes #2973

Changes proposed in this pull request

  • This change handles scenarios where equality operator types like in and has contain + character enclosed within brackets in filter expressions.
  • It also handles scenarios where function operator types like startsWith contain + characters).
image

@timayabi2020 timayabi2020 requested a review from a team as a code owner October 17, 2024 16:37
@timayabi2020 timayabi2020 linked an issue Oct 17, 2024 that may be closed by this pull request
@@ -29,7 +29,7 @@ internal static string UnescapeString(this PSCmdlet cmdlet, string value)
try
{
var unescapedString = Uri.UnescapeDataString(value);
return value.EndsWith("'") ? unescapedString: unescapedString.Replace('+', ' ');
return (value.EndsWith("'") || value.EndsWith("')")) ? unescapedString: unescapedString.Replace('+', ' ');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to capture these scenarios in a test to prevent a regression in the future?

Copy link
Contributor Author

@timayabi2020 timayabi2020 Oct 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be tricky because the extension method a cmdlet derived from PSCmdlet class and cmdlets derived from the PSCmdlet class in PowerShell cannot be invoked directly because they are designed to be used within the context of a PowerShell runtime environment.

For example in a unit test we will need to have something like the code below calling a cmdlet implementation.

        var cmdlet = new CommandA();
        cmdlet.Value = "('Khalayi+mzuri')";
        cmdlet.Invoke();

The above won't work because we will not have a PowerShell run time which PSmdlet class depends on.

Below is the cmdlet implementation which we hope it can use the extension method.

using System.Management.Automation;

public class CommandA : PSCmdlet
{
    [Parameter(Position = 0, Mandatory = true)]
    public string Value { get; set; }

    protected override void ProcessRecord()
    {
       WriteObject(this.UnescapeString(Value));
    }
}

This is one of the limitations we currently having when it comes to writing unit testing some an extension method expecting a Cmdlet class.

For now we can only rely on manual tests after the cmldets have been generated. However, suggestions on how to go about this are much welcomed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filter is incorrectly handling special characters
2 participants