Skip to content

Backslashes in subject or expected result are not correctly shown in the message #986

@rubenrorije

Description

@rubenrorije

Description

It seems that when running a test on a string variable backslashes are escaped incorrectly. Especially trailing backslashes are removed from the message.

Complete minimal example reproducing the issue

See multiple unit tests in this gist: https://gist.github.com/rubenrorije/2caf183ffb7e598546d220797252795c

One of the examples of the unit tests:

[TestMethod]
public void Trailing_Backslash_In_Expected_Result_Should_Not_Be_Removed()
{
    "A".Should().Be("A\\");
    /*
     * Output:
     * Expected string to be "A" with a length of 2, but "A" has a length of 1, differs near "A" (index 0).
     * Expected Output:
     * Expected string to be "A\" with a length of 2, but "A" has a length of 1, differs near "A" (index 0).
     */
}

Versions

Fluent Assertions 5.5.3
.Net Framework 4.6.1

Remarks

I would have looked for myself whether this was something that I could solve myself and include a pull-request. But at the moment (travelling in Iran) I do not have reliable internet connection to do this.
Either someone else can take a look, or when I have the opportunity I will look into it more.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions