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

Guard against unformattable caller name #1788

Merged
merged 1 commit into from Jan 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 8 additions & 1 deletion Src/FluentAssertions/Execution/MessageBuilder.cs
Expand Up @@ -91,7 +91,14 @@ private string FormatArgumentPlaceholders(string failureMessage, object[] failur
{
string[] values = failureArgs.Select(a => Formatter.ToString(a, formattingOptions)).ToArray();

return string.Format(CultureInfo.InvariantCulture, failureMessage, values);
try
{
return string.Format(CultureInfo.InvariantCulture, failureMessage, values);
}
catch (FormatException formatException)
{
return $"**WARNING** failure message '{failureMessage}' could not be formatted with string.Format{Environment.NewLine}{formatException.StackTrace}";
}
}

private string SanitizeReason(string reason)
Expand Down
1 change: 1 addition & 0 deletions docs/_pages/releases.md
Expand Up @@ -21,6 +21,7 @@ sidebar:
* `OccurredEvent` ordering on monitored object is now done via thread-safe counter - [#1773](https://github.com/fluentassertions/fluentassertions/pull/1773)
* Avoid a `NullReferenceException` when testing an application compiled with .NET Native - [#1776](https://github.com/fluentassertions/fluentassertions/pull/1776)
* `[Not]Contain(key, value)` for dictionary-like enumerables incorrectly checked if the key was present - [#1786](https://github.com/fluentassertions/fluentassertions/pull/1786)
* Avoid throwing a `FormatException` when caller name determination returns an unformattable string - [#1788](https://github.com/fluentassertions/fluentassertions/pull/1788)

## 6.3.0

Expand Down