Fix a formatting exception when {} is used as a dictionary key.#3008
Fix a formatting exception when {} is used as a dictionary key.#3008dennisdoomen wants to merge 1 commit intofluentassertions:support-7.0from
Conversation
3a4911f to
955dafc
Compare
Pull Request Test Coverage Report for Build 13420695412Details
💛 - Coveralls |
Qodana for .NET2 new problems were found
💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at [email protected]
|
|
Should the latest SAVEPOINT commit be reverted from this branch? |
877c451 to
b2b446d
Compare
b729b9c to
9fe43a7
Compare
Screwed up my branches. Should be fine now. |
bac0db7 to
1479f04
Compare
1479f04 to
3406800
Compare
3406800 to
0bbe8a7
Compare
| // 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.,%‰+-\\'"";]+)?\}+"); |
There was a problem hiding this comment.
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.
0bbe8a7 to
ff19864
Compare
ff19864 to
6d8d1b0
Compare
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
EscapePlaceholdersunnecessary. With this, strings like{}in dictionary keys will no longer cause crashes.Resolves #2704