| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
…tate when option assignment fails
Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
Co-authored-by: dkontyko <33853225+dkontyko@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sorry, something went wrong.
There was a problem hiding this comment.
This pull request fixes a Set-Variable -Force edge case where ReadOnly was temporarily removed to perform an update, but not restored when a subsequent option update (notably -Option Constant) failed. It also adds regression/compatibility tests to lock in the intended behavior for issue #27679 cases 1–3.
Changes:
| File | Description |
|---|---|
| src/Microsoft.PowerShell.Commands.Utility/commands/utility/Var.cs | Tracks whether ReadOnly was temporarily cleared and restores it in the handled exception paths when option updates fail. |
| test/powershell/Modules/Microsoft.PowerShell.Utility/Set-Variable.Tests.ps1 | Adds regression/compatibility tests covering the issue #27679 scenarios and option combinations. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
Sorry, something went wrong.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 15243fcb-972e-4518-b3b2-e0c5021b4199
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3068dc60-7ac0-4d2b-bcc3-020ac4816d67
| Back | FazBrowse Home | New Git URL |
PR Summary
Restore the ReadOnly option when Set-Variable -Force temporarily removes it and a subsequent option update fails.
Add regression coverage for ReadOnly, ReadOnly | Private, and ReadOnly | AllScope, plus compatibility tests documenting the intentionally retained behavior for cases 1 and 2 of #27679.
PR Context
When Set-Variable -Force operates on a ReadOnly variable, it temporarily removes ReadOnly before applying the requested changes. If applying -Option Constant fails with VariableCannotBeMadeConstant, the temporary removal was not reverted, leaving the variable writable.
This change restores ReadOnly in the existing handled exception paths while preserving other current option flags. It addresses case 3 of #27679, as agreed by the PowerShell cmdlets working group.
For backward compatibility, cases 1 and 2 continue to retain value and description changes made before the option update fails. Tests document this behavior explicitly.
PR Checklist