diff options
| author | crobibero <cody@robibe.ro> | 2020-10-16 09:37:35 -0600 |
|---|---|---|
| committer | crobibero <cody@robibe.ro> | 2020-10-16 09:37:35 -0600 |
| commit | b2662894cf6e7e6b20d12ff22c79ee5159658a2a (patch) | |
| tree | 7cc9b2cc90947ac5e769384d1c1da5458af8ca5f | |
| parent | 7565ae22cb91c472928167ac89c39f67324c72e1 (diff) | |
Add whitespace handling and tests
| -rw-r--r-- | MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs | 2 | ||||
| -rw-r--r-- | tests/Jellyfin.Common.Tests/Json/JsonCommaDelimitedArrayTests.cs | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs b/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs index 4f6a68531..bf7048c37 100644 --- a/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs +++ b/MediaBrowser.Common/Json/Converters/JsonCommaDelimitedArrayConverter.cs @@ -35,7 +35,7 @@ namespace MediaBrowser.Common.Json.Converters var entries = new T[stringEntries.Length]; for (var i = 0; i < stringEntries.Length; i++) { - entries[i] = (T)_typeConverter.ConvertFrom(stringEntries[i]); + entries[i] = (T)_typeConverter.ConvertFrom(stringEntries[i].Trim()); } return entries; diff --git a/tests/Jellyfin.Common.Tests/Json/JsonCommaDelimitedArrayTests.cs b/tests/Jellyfin.Common.Tests/Json/JsonCommaDelimitedArrayTests.cs index c543cfee9..16f8a690e 100644 --- a/tests/Jellyfin.Common.Tests/Json/JsonCommaDelimitedArrayTests.cs +++ b/tests/Jellyfin.Common.Tests/Json/JsonCommaDelimitedArrayTests.cs @@ -22,6 +22,19 @@ namespace Jellyfin.Common.Tests.Json } [Fact] + public static void Deserialize_String_Space_Valid_Success() + { + var desiredValue = new GenericBodyModel<string> + { + Value = new[] { "a", "b", "c" } + }; + + var options = new JsonSerializerOptions(); + var value = JsonSerializer.Deserialize<GenericBodyModel<string>>(@"{ ""Value"": ""a, b, c"" }", options); + Assert.Equal(desiredValue.Value, value?.Value); + } + + [Fact] public static void Deserialize_GenericCommandType_Valid_Success() { var desiredValue = new GenericBodyModel<GeneralCommandType> @@ -36,6 +49,20 @@ namespace Jellyfin.Common.Tests.Json } [Fact] + public static void Deserialize_GenericCommandType_Space_Valid_Success() + { + var desiredValue = new GenericBodyModel<GeneralCommandType> + { + Value = new[] { GeneralCommandType.MoveUp, GeneralCommandType.MoveDown } + }; + + var options = new JsonSerializerOptions(); + options.Converters.Add(new JsonStringEnumConverter()); + var value = JsonSerializer.Deserialize<GenericBodyModel<GeneralCommandType>>(@"{ ""Value"": ""MoveUp, MoveDown"" }", options); + Assert.Equal(desiredValue.Value, value?.Value); + } + + [Fact] public static void Deserialize_String_Array_Valid_Success() { var desiredValue = new GenericBodyModel<string> |
