Skip to content

issue-468: Fix empty/whitespace string converting to array type#469

Merged
nblumhardt merged 3 commits intoserilog:devfrom
gyurebalint-CID:fix/issue-468
Apr 9, 2026
Merged

issue-468: Fix empty/whitespace string converting to array type#469
nblumhardt merged 3 commits intoserilog:devfrom
gyurebalint-CID:fix/issue-468

Conversation

@gyurebalint-CID
Copy link
Copy Markdown
Contributor

Fixes #468

Problem

When a configuration value is an empty or whitespace-only string and the target type is an array (e.g. string[]), StringArgumentValue.ConvertTo falls through to parsing logic that produces unexpected results instead of returning an empty array.

Changes

StringArgumentValue.cs

  • Changed string.IsNullOrEmpty to string.IsNullOrWhiteSpace in the array-type guard, so that empty ("") and whitespace-only (" ") values both return an empty array.

StringArgumentValueTests.cs

Why IsNullOrWhiteSpace over IsNullOrEmpty?

A whitespace-only string like " " is not meaningful array content. Without this, it would fall through and produce an array containing a whitespace string — a subtle bug. No one intentionally configures " " as valid array input; if structured values are needed, JSON arrays should be used instead.

@gyurebalint
Copy link
Copy Markdown
Contributor

Hello everyone.
I think CI/CD needs approval for it to run.
If you have any comments, changes in mind, let me know and I'll adopt them.
Along with my other PR on a similar issue in this repo.
This is my private account, this PR was created with my work one.

@nblumhardt
Copy link
Copy Markdown
Member

Thanks @gyurebalint-CID 👍

@nblumhardt nblumhardt merged commit 955b652 into serilog:dev Apr 9, 2026
1 check passed
@nblumhardt nblumhardt mentioned this pull request Apr 30, 2026
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.

InvalidCastException when enricher Args contains empty JSON array for params string[] parameter (regression in .NET 10)

3 participants