Skip to content

Fix #2953: fail open when a bound parameter's ToString throws in the mock filter serializer - #2955

Merged
nohwnd merged 1 commit into
pester:mainfrom
nohwnd:fix-2953-filter-tostring
Aug 6, 2026
Merged

Fix #2953: fail open when a bound parameter's ToString throws in the mock filter serializer#2955
nohwnd merged 1 commit into
pester:mainfrom
nohwnd:fix-2953-filter-tostring

Conversation

@nohwnd

@nohwnd nohwnd commented Aug 6, 2026

Copy link
Copy Markdown
Member

Fix #2953

Test-ParameterFilter serializes the bound parameters into diagnostic text (the debug message and the failed-filter summary), and that called ToString on every value. If a value's ToString throws, for example a mocked SMO type created by New-MockObject, the filter threw even when the value was never referenced by the filter.

Each value now goes through a small helper that catches the failure and falls back to a placeholder, so building the diagnostic text can never take down the mock.

Added a test that mocks a command with a non-matching parameter filter and passes a value whose ToString throws.

🤖

…n the mock filter serializer

Test-ParameterFilter builds diagnostic text from the bound parameters,
which called ToString on every value. A value whose ToString throws (for
example a mocked SMO type created by New-MockObject) made the whole filter
throw, even when the value was not referenced by the filter at all.

Serialize each value through a small helper that catches the failure and
falls back to a placeholder, so the diagnostic text can never take down the
mock.
@nohwnd
nohwnd enabled auto-merge (squash) August 6, 2026 18:56
@nohwnd nohwnd added this to the 6.1.0 milestone Aug 6, 2026
@nohwnd
nohwnd disabled auto-merge August 6, 2026 19:19
@nohwnd
nohwnd merged commit e51d9d3 into pester:main Aug 6, 2026
11 checks passed
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.

Unsafe parameter serialization in Test-ParameterFilter

1 participant