-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Replace Operator InvalidOperation Exception Message #12333
Copy link
Copy link
Closed
Labels
First-Time-IssueEasy issues first time contributors can work on to learn about this projectEasy issues first time contributors can work on to learn about this projectIssue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalitythe issue is for cleaning up the code with no impact on functionalityResolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Metadata
Metadata
Assignees
Labels
First-Time-IssueEasy issues first time contributors can work on to learn about this projectEasy issues first time contributors can work on to learn about this projectIssue-Code Cleanupthe issue is for cleaning up the code with no impact on functionalitythe issue is for cleaning up the code with no impact on functionalityResolution-FixedThe issue is fixed.The issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Enginecore PowerShell engine, interpreter, and runtimecore PowerShell engine, interpreter, and runtime
Steps to reproduce
There are three variations of the Replacement Operator:
-replaceis implicitly case-insensitive.-ireplaceis explicitly case-insensitive.-creplaceis case-sensitive.The exception message returned when passing three or more comma separated values to
-replace,-ireplaceor-creplaceis counterintuitive:"foo" -replace "o", "e", "e"InvalidOperation: The -ireplace operator allows only two elements to follow it, not 3."foo" -ireplace "o", "e", "e"InvalidOperation: The -ireplace operator allows only two elements to follow it, not 3."foo" -creplace "o", "e", "e"InvalidOperation: The -replace operator allows only two elements to follow it, not 3.As the table above demonstrates, when either the
-replaceor-ireplaceoperator is used, the message content refers to-ireplace. This is not ideal but since-replaceand-ireplaceare functionally equivalent it's perhaps not a big deal. But what is particularly inappropriate is that the exception message for-creplacerefers to-replace.Expected behavior
The exception message should ideally refer to the respective operator that was used. Else at a minimum, the message returned for the
-creplaceoperator should refer to-creplace.Environment data
The same result is exhibited in PowerShell 5.1, 7.0.0 and 7.1.0-preview.1, full version details below: