Browse Source

change assumptions around whitespace strings

pull/1348/head
Chris Johnston 6 years ago
parent
commit
426190c940
2 changed files with 7 additions and 5 deletions
  1. +4
    -2
      src/Discord.Net.Core/Format.cs
  2. +3
    -3
      test/Discord.Net.Tests.Unit/FormatTests.cs

+ 4
- 2
src/Discord.Net.Core/Format.cs View File

@@ -47,8 +47,10 @@ namespace Discord
/// <returns>Gets the formatted quote text.</returns> // TODO: better xmldoc /// <returns>Gets the formatted quote text.</returns> // TODO: better xmldoc
public static string Quote(string text) 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(); StringBuilder result = new StringBuilder();




+ 3
- 3
test/Discord.Net.Tests.Unit/FormatTests.cs View File

@@ -35,9 +35,9 @@ namespace Discord
Assert.Null(Format.Quote(null)); Assert.Null(Format.Quote(null));
} }
[Theory] [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 [InlineData("input", "> input")] // single line
// should work with CR or CRLF // should work with CR or CRLF
[InlineData("inb4\ngreentext", "> inb4\n> greentext")] [InlineData("inb4\ngreentext", "> inb4\n> greentext")]


Loading…
Cancel
Save