From 426190c940aac4282fc37aeb6c7fabb29108290e Mon Sep 17 00:00:00 2001 From: Chris Johnston Date: Thu, 25 Jul 2019 07:36:52 -0700 Subject: [PATCH] change assumptions around whitespace strings --- src/Discord.Net.Core/Format.cs | 6 ++++-- test/Discord.Net.Tests.Unit/FormatTests.cs | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Discord.Net.Core/Format.cs b/src/Discord.Net.Core/Format.cs index 49d34613e..55161b21d 100644 --- a/src/Discord.Net.Core/Format.cs +++ b/src/Discord.Net.Core/Format.cs @@ -47,8 +47,10 @@ namespace Discord /// Gets the formatted quote text. // TODO: better xmldoc public static string Quote(string text) { - if (text == null) - return null; + // do not modify null or whitespace text + // whitespace does not get quoted properly + if (string.IsNullOrWhiteSpace(text)) + return text; StringBuilder result = new StringBuilder(); diff --git a/test/Discord.Net.Tests.Unit/FormatTests.cs b/test/Discord.Net.Tests.Unit/FormatTests.cs index 7877d5fdc..c3737af8e 100644 --- a/test/Discord.Net.Tests.Unit/FormatTests.cs +++ b/test/Discord.Net.Tests.Unit/FormatTests.cs @@ -35,9 +35,9 @@ namespace Discord Assert.Null(Format.Quote(null)); } [Theory] - [InlineData("", "> ")] - [InlineData("\n", "> \n")] - [InlineData("\n ", "> \n> ")] + [InlineData("", "")] + [InlineData("\n", "\n")] + [InlineData("foo\n\nbar", "> foo\n> \n> bar")] [InlineData("input", "> input")] // single line // should work with CR or CRLF [InlineData("inb4\ngreentext", "> inb4\n> greentext")]