Skip to content

Conversation

@dennisdoomen
Copy link
Member

@dennisdoomen dennisdoomen commented Feb 8, 2025

This pull request includes several changes to improve the handling of placeholders and formatting in various parts of the codebase, making a lot of calls to EscapePlaceholders unnecessary. With this, strings like {} in dictionary keys will no longer cause crashes.

Resolves #2704

@dennisdoomen dennisdoomen modified the milestones: 7.2.0, 8.1.0 Feb 8, 2025
@dennisdoomen dennisdoomen force-pushed the fix/2704-formatting-crash branch from 3a4911f to 955dafc Compare February 8, 2025 13:38
@coveralls
Copy link

coveralls commented Feb 8, 2025

Pull Request Test Coverage Report for Build 13420695412

Details

  • 32 of 35 (91.43%) changed or added relevant lines in 9 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.009%) to 97.057%

Changes Missing Coverage Covered Lines Changed/Added Lines %
Src/FluentAssertions/Execution/MessageBuilder.cs 17 20 85.0%
Totals Coverage Status
Change from base Build 13258224722: -0.009%
Covered Lines: 13030
Relevant Lines: 13290

💛 - Coveralls

@github-actions
Copy link

github-actions bot commented Feb 8, 2025

Qodana for .NET

2 new problems were found

Inspection name Severity Problems
Redundant using directive 🔶 Warning 2

💡 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

@jnyrup
Copy link
Member

jnyrup commented Feb 10, 2025

Should the latest SAVEPOINT commit be reverted from this branch?

@dennisdoomen dennisdoomen force-pushed the fix/2704-formatting-crash branch from 877c451 to b2b446d Compare February 10, 2025 21:05
@dennisdoomen dennisdoomen force-pushed the fix/2704-formatting-crash branch 2 times, most recently from b729b9c to 9fe43a7 Compare February 11, 2025 07:26
@dennisdoomen dennisdoomen requested a review from jnyrup February 11, 2025 07:38
@dennisdoomen
Copy link
Member Author

Should the latest SAVEPOINT commit be reverted from this branch?

Screwed up my branches. Should be fine now.

@dennisdoomen dennisdoomen force-pushed the fix/2704-formatting-crash branch from 1479f04 to 3406800 Compare February 14, 2025 17:36
@dennisdoomen dennisdoomen requested a review from jnyrup February 14, 2025 17:37
@dennisdoomen dennisdoomen force-pushed the fix/2704-formatting-crash branch from 3406800 to 0bbe8a7 Compare February 14, 2025 19:00
// Matches the .NET string format {index[,alignment][:formatString]}, even
// if the opening and closing curly braces are escaped themselves.
var matches = Regex.Matches(message,
@"\{+[0-9]+(,-?[0-9]+)?(:[a-zA-z.,%‰+-\\'"";]+)?\}+");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where did you find this regex?
(It also has a bug A-z should be A-Z)

E.g. {0:µ} is a valid formatString.

According to the implementation the formatString can be anything except { and }.

Here's another set of tests where the two last still fail with this PR as we mistake them with placeholders.

[Theory]
[InlineData("{")]
[InlineData("}")]
[InlineData("{}")]
[InlineData("{0}")]
[InlineData("{{0}}")]
public void Can_handle_braces_in_dictionary_keys(string key)
{
    // Arrange
    var subject = new Dictionary<string, string> { [key] = "" };
    var expectation = new Dictionary<string, string> { [key] = null };

    // Act
    var act = () => expectation.Should().BeEquivalentTo(subject);

    // Assert
    act.Should().Throw<XunitException>()
        .WithMessage($"Expected expectation[{key}] to be \"\", but found <null>.*");
}

I think the only proper way to solve this would be to avoid early string interpolation.
Anything else will probably be a lost game that only adds complexity and fragility.

@dennisdoomen dennisdoomen force-pushed the fix/2704-formatting-crash branch from 0bbe8a7 to ff19864 Compare February 18, 2025 18:53
@dennisdoomen dennisdoomen force-pushed the fix/2704-formatting-crash branch from ff19864 to 6d8d1b0 Compare February 19, 2025 19:23
@dennisdoomen dennisdoomen modified the milestones: 7.2.0, 8.1.0 Feb 19, 2025
@dennisdoomen dennisdoomen deleted the branch fluentassertions:support-7.0 February 20, 2025 17:37
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