{"action":"created","issue":{"url":"https://api.github.com/repos/fluentassertions/fluentassertions/issues/756","repository_url":"https://api.github.com/repos/fluentassertions/fluentassertions","labels_url":"https://api.github.com/repos/fluentassertions/fluentassertions/issues/756/labels{/name}","comments_url":"https://api.github.com/repos/fluentassertions/fluentassertions/issues/756/comments","events_url":"https://api.github.com/repos/fluentassertions/fluentassertions/issues/756/events","html_url":"https://github.com/fluentassertions/fluentassertions/issues/756","id":295363179,"number":756,"title":"FormatException when a bad string is included in the 'because' clause of a failed assertion","user":{"login":"bernard-chen","id":911462,"avatar_url":"https://avatars2.githubusercontent.com/u/911462?v=4","gravatar_id":"","url":"https://api.github.com/users/bernard-chen","html_url":"https://github.com/bernard-chen","followers_url":"https://api.github.com/users/bernard-chen/followers","following_url":"https://api.github.com/users/bernard-chen/following{/other_user}","gists_url":"https://api.github.com/users/bernard-chen/gists{/gist_id}","starred_url":"https://api.github.com/users/bernard-chen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bernard-chen/subscriptions","organizations_url":"https://api.github.com/users/bernard-chen/orgs","repos_url":"https://api.github.com/users/bernard-chen/repos","events_url":"https://api.github.com/users/bernard-chen/events{/privacy}","received_events_url":"https://api.github.com/users/bernard-chen/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-02-08T02:24:26Z","updated_at":"2018-02-08T06:02:33Z","closed_at":null,"author_association":"NONE","body":"When a particular string is included in the because clause of a failed assertion, it causes the assertion to throw a FormatException instead of an AssertionFailedException. This string comes from the big list of naughty strings (https://github.com/minimaxir/big-list-of-naughty-strings) and corresponds to \"<>?:\\\"{}|_+\".\r\n\r\nThis problem can be reproduced with the following .NET Core 2.0 console app with a reference to the 5.0 version of FluentAssertions:\r\n\r\n```\r\nusing FluentAssertions;\r\nusing FluentAssertions.Execution;\r\n\r\nnamespace BadStringForFluentAssertions\r\n{\r\n    class Program\r\n    {\r\n        static void Main(string[] args)\r\n        {\r\n            // When decoded, this string is \"<>?:\\\"{}|_+\"\r\n            const string base64Encoded = \"PD4/OiJ7fXxfKw==\";\r\n            var troublesomeString = System.Text.Encoding.UTF8.GetString(System.Convert.FromBase64String(base64Encoded));\r\n\r\n            // This assertion throws a format exception rather than the correct AssertionFailedException\r\n            System.Action a = () =>\r\n                troublesomeString.Should().Be(\"foo\", $\"{troublesomeString} causes trouble in the 'because' clause\");\r\n\r\n            a.Should().Throw<AssertionFailedException>();\r\n        }\r\n    }\r\n}\r\n\r\n```\r\n\r\nThe actual error I get is:\r\n\r\n```\r\nFluentAssertions.Execution.AssertionFailedException\r\n  HResult=0x80131500\r\n  Message=Expected a <FluentAssertions.Execution.AssertionFailedException> to be thrown, but found a <System.FormatException>: System.FormatException with message \"Input string was not in a correct format.\"\r\n     at System.Text.StringBuilder.FormatError()\r\n     at System.Text.StringBuilder.AppendFormatHelper(IFormatProvider provider, String format, ParamsArray args)\r\n     at System.String.FormatHelper(IFormatProvider provider, String format, ParamsArray args)\r\n     at System.String.Format(String format, Object[] args)\r\n     at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Execution\\AssertionScope.cs:line 208\r\n     at FluentAssertions.Primitives.StringEqualityValidator.ValidateAgainstLengthDifferences() in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Primitives\\StringEqualityValidator.cs:line 30\r\n     at FluentAssertions.Primitives.StringValidator.Validate() in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Primitives\\StringValidator.cs:line 41\r\n     at FluentAssertions.Primitives.StringAssertions.Be(String expected, String because, Object[] becauseArgs) in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Primitives\\StringAssertions.cs:line 41\r\n     at BadStringForFluentAssertions.Program.<>c__DisplayClass0_0.<Main>b__0() in d:\\dev\\BadStringForFluentAssertions\\BadStringForFluentAssertions\\Program.cs:line 16\r\n     at FluentAssertions.Specialized.ActionAssertions.InvokeSubjectWithInterception() in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Specialized\\ActionAssertions.cs:line 118\r\n.\r\n  Source=FluentAssertions\r\n  StackTrace:\r\n   at FluentAssertions.Execution.FallbackTestFramework.Throw(String message) in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Execution\\FallbackTestFramework.cs:line 21\r\n   at FluentAssertions.Execution.AssertionScope.FailWith(String message, Object[] args) in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Execution\\AssertionScope.cs:line 215\r\n   at FluentAssertions.Specialized.ActionAssertions.Throw[TException](String because, Object[] becauseArgs) in C:\\projects\\fluentassertions-vf06b\\Src\\FluentAssertions\\Specialized\\ActionAssertions.cs:line 60\r\n   at BadStringForFluentAssertions.Program.Main(String[] args) in d:\\dev\\BadStringForFluentAssertions\\BadStringForFluentAssertions\\Program.cs:line 18\r\n\r\n```\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/fluentassertions/fluentassertions/issues/comments/364011724","html_url":"https://github.com/fluentassertions/fluentassertions/issues/756#issuecomment-364011724","issue_url":"https://api.github.com/repos/fluentassertions/fluentassertions/issues/756","id":364011724,"user":{"login":"dennisdoomen","id":572734,"avatar_url":"https://avatars3.githubusercontent.com/u/572734?v=4","gravatar_id":"","url":"https://api.github.com/users/dennisdoomen","html_url":"https://github.com/dennisdoomen","followers_url":"https://api.github.com/users/dennisdoomen/followers","following_url":"https://api.github.com/users/dennisdoomen/following{/other_user}","gists_url":"https://api.github.com/users/dennisdoomen/gists{/gist_id}","starred_url":"https://api.github.com/users/dennisdoomen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/dennisdoomen/subscriptions","organizations_url":"https://api.github.com/users/dennisdoomen/orgs","repos_url":"https://api.github.com/users/dennisdoomen/repos","events_url":"https://api.github.com/users/dennisdoomen/events{/privacy}","received_events_url":"https://api.github.com/users/dennisdoomen/received_events","type":"User","site_admin":false},"created_at":"2018-02-08T06:02:33Z","updated_at":"2018-02-08T06:02:33Z","author_association":"OWNER","body":"Thanks for reporting this. Out of curiosity, is this just a made-up example, or are you actually trying to include the expectation in the _because_ parameter?"}}
{"actor":{"display_login":"dennisdoomen"}}