diff --git a/BlazorComponentUtilities.Tests/CssBuilderTests.cs b/BlazorComponentUtilities.Tests/CssBuilderTests.cs index 908317e..046f4be 100644 --- a/BlazorComponentUtilities.Tests/CssBuilderTests.cs +++ b/BlazorComponentUtilities.Tests/CssBuilderTests.cs @@ -133,6 +133,23 @@ public void ShouldNotThrowWhenNullFor_BuildClassesFromAttributes() } } + [Fact] + public void ShouldNotThrowWhenNullForAttributeItem_BuildClassesFromAttributes() + { + { + //arrange + // Simulates Razor Components attribute splatting feature + IReadOnlyDictionary attributes = new Dictionary { { "class", null } }; + + //act + var ClassToRender = new CssBuilder("item-one") + .AddClassFromAttributes(attributes) + .Build(); + //assert + ClassToRender.Should().Be("item-one"); + } + } + [Fact] public void ForceNullForWhitespace_BuildClassesFromAttributes() { diff --git a/BlazorComponentUtilities/BlazorComponentUtilities.csproj b/BlazorComponentUtilities/BlazorComponentUtilities.csproj index e1856ba..9bdb593 100644 --- a/BlazorComponentUtilities/BlazorComponentUtilities.csproj +++ b/BlazorComponentUtilities/BlazorComponentUtilities.csproj @@ -15,12 +15,15 @@ Ed Charbeneau BlazorPro BlazorComponentUtilities CssBuilder - 1.7.1 - Fixed trivial performance issue with redundant assignment when building strings -1.7.0 - Added SetPrefix method to reduce reptititive class prefixing -1.6.0 - Added Func<string> value overload for ValueBuilder + + 1.8.0 + Fixed null ref error when using AddClassFromAttributes and passing a null attribute value. + 1.7.1 + Fixed trivial performance issue with redundant assignment when building strings + 1.7.0 + Added SetPrefix method to reduce reptititive class prefixing + 1.6.0 + Added Func<string> value overload for ValueBuilder 1.5.0 Added Func<string> value overload for StyleBuilder Minor performance improvements for .Add*Attributes @@ -32,10 +35,10 @@ Added utility method for returning null for empty strings. This is useful for splatting scenarios. Added utility method for starting off new builders. - 1.7.1 + 1.8.0 blazor-glove-256.jpg - 1.7.1.0 - 1.7.1.0 + 1.8.0.0 + 1.8.0.0 diff --git a/BlazorComponentUtilities/CssBuilder.cs b/BlazorComponentUtilities/CssBuilder.cs index 6ecffd9..2fc86ec 100644 --- a/BlazorComponentUtilities/CssBuilder.cs +++ b/BlazorComponentUtilities/CssBuilder.cs @@ -117,7 +117,7 @@ public CssBuilder AddValue(string value) /// CssBuilder public CssBuilder AddClassFromAttributes(IReadOnlyDictionary additionalAttributes) => additionalAttributes == null ? this : - additionalAttributes.TryGetValue("class", out var c) ? AddClass(c.ToString()) : this; + additionalAttributes.TryGetValue("class", out var c) && c != null ? AddClass(c.ToString()) : this; /// /// Finalize the completed CSS Classes as a string.