Skip to content

Prevent a crash while formatting a collection with nested empty collections#3150

Merged
dennisdoomen merged 1 commit intofluentassertions:support-7.0from
dennisdoomen:fix-3148
Feb 7, 2026
Merged

Prevent a crash while formatting a collection with nested empty collections#3150
dennisdoomen merged 1 commit intofluentassertions:support-7.0from
dennisdoomen:fix-3148

Conversation

@dennisdoomen
Copy link
Copy Markdown
Member

@dennisdoomen dennisdoomen commented Jan 21, 2026

This change hardens the object/collection formatter against a crash when it tries to splice a rendered fragment into an existing line but the calculated insertion index is past the end of the target string (now clamped to a valid range to avoid IndexOutOfRangeException).

The side-effect of this work is that spacing at the end of failure message is removed, which is something that was fix by the redesign of the formatting logic. For this hotfix, I had to take a less perfect approach.

Note This bug does not exist on v8 and can be discarded while upmerging.

Fixes #3148

@github-actions
Copy link
Copy Markdown

github-actions bot commented Jan 21, 2026

Qodana for .NET

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked
☁️ View the detailed Qodana report

Contact Qodana team

Contact us at qodana-support@jetbrains.com

@dennisdoomen dennisdoomen force-pushed the fix-3148 branch 2 times, most recently from dec65d2 to fa3e82a Compare January 21, 2026 20:30
@dennisdoomen dennisdoomen added this to the 7.2.1 milestone Jan 22, 2026
@dennisdoomen dennisdoomen force-pushed the fix-3148 branch 3 times, most recently from dae635e to dd9d95d Compare January 23, 2026 20:37
@dennisdoomen dennisdoomen marked this pull request as ready for review January 23, 2026 20:41
@dennisdoomen dennisdoomen requested a review from jnyrup January 23, 2026 20:41
@dennisdoomen dennisdoomen changed the title Prevent a crash while formatting a collection with nested empty subco… Prevent a crash while formatting a collection with nested empty collections Jan 23, 2026
@coveralls
Copy link
Copy Markdown

coveralls commented Jan 23, 2026

Pull Request Test Coverage Report for Build 21785475175

Details

  • 19 of 19 (100.0%) changed or added relevant lines in 3 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.002%) to 97.068%

Totals Coverage Status
Change from base Build 13751651565: 0.002%
Covered Lines: 13031
Relevant Lines: 13289

💛 - Coveralls

…llections

- Prevents potential IndexOutOfRangeException in `FormattedObjectGraph` by using `Math.Min` for string insertion.
- Improves formatting consistency of test expectations by removing unnecessary whitespace.
- Adds a test to ensure rendering of empty nested collections does not crash.
This was referenced Mar 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants