From ff1e6792b82d1358ac063730ebc4d2e577db62d9 Mon Sep 17 00:00:00 2001 From: Robert Linde Date: Fri, 3 Sep 2021 08:31:37 +0200 Subject: [PATCH] Fix asset rendering with null file --- .../Contentful.AspNetCore.csproj | 8 +++---- .../Models/Rendering/HtmlRenderTests.cs | 21 +++++++++++++++++++ Contentful.Core/Contentful.Core.csproj | 6 +++--- Contentful.Core/Models/Authoring.cs | 3 ++- 4 files changed, 30 insertions(+), 8 deletions(-) diff --git a/Contentful.AspNetCore/Contentful.AspNetCore.csproj b/Contentful.AspNetCore/Contentful.AspNetCore.csproj index fcff029..528f934 100644 --- a/Contentful.AspNetCore/Contentful.AspNetCore.csproj +++ b/Contentful.AspNetCore/Contentful.AspNetCore.csproj @@ -13,10 +13,10 @@ https://github.com/contentful/contentful.net MIT git - 6.0.12 - 6.0.12.0 + 6.0.13 + 6.0.13.0 https://github.com/contentful/contentful.net - 6.0.12.0 + 6.0.13.0 bin\Release\netstandard1.5\Contentful.AspNetCore.xml @@ -25,7 +25,7 @@ $(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb - + all runtime; build; native; contentfiles; analyzers diff --git a/Contentful.Core.Tests/Models/Rendering/HtmlRenderTests.cs b/Contentful.Core.Tests/Models/Rendering/HtmlRenderTests.cs index ec81fcc..68be5ce 100644 --- a/Contentful.Core.Tests/Models/Rendering/HtmlRenderTests.cs +++ b/Contentful.Core.Tests/Models/Rendering/HtmlRenderTests.cs @@ -141,5 +141,26 @@ public async Task ListItemRendererShouldRespectRendererOptions(bool omitParagrap //Assert Assert.Equal(expectedResult, result); } + + [Fact] + public void AssetShouldRenderEmptyLinkWithNoFile() + { + //Arrange + var renderer = new AssetRenderer(null); + var assetStructure = new AssetStructure + { + Content = new List(), + Data = new AssetStructureData + { + Target = new Asset() + }, + NodeType = "" + }; + + //Act + var html = renderer.Render(assetStructure); + //Assert + Assert.Equal("", html); + } } } \ No newline at end of file diff --git a/Contentful.Core/Contentful.Core.csproj b/Contentful.Core/Contentful.Core.csproj index 236500c..f092ecd 100644 --- a/Contentful.Core/Contentful.Core.csproj +++ b/Contentful.Core/Contentful.Core.csproj @@ -18,9 +18,9 @@ false false false - 6.0.12.0 - 6.0.12.0 - 6.0.12 + 6.0.13.0 + 6.0.13.0 + 6.0.13 diff --git a/Contentful.Core/Models/Authoring.cs b/Contentful.Core/Models/Authoring.cs index cf2a0db..fa07e80 100644 --- a/Contentful.Core/Models/Authoring.cs +++ b/Contentful.Core/Models/Authoring.cs @@ -643,7 +643,8 @@ public string Render(IContent content) sb.Append($"\"{asset.Title}\""); }else { - sb.Append($""); + var url = asset.File?.Url; + sb.Append(string.IsNullOrEmpty(url)? "" : $""); if (assetStructure.Content != null && assetStructure.Content.Any()) {