Skip to content

Commit

Permalink
Fix asset rendering with null file
Browse files Browse the repository at this point in the history
  • Loading branch information
Roblinde committed Sep 3, 2021
1 parent af6781f commit ff1e679
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Contentful.AspNetCore/Contentful.AspNetCore.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
<PackageProjectUrl>https://github.com/contentful/contentful.net</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RepositoryType>git</RepositoryType>
<Version>6.0.12</Version>
<AssemblyVersion>6.0.12.0</AssemblyVersion>
<Version>6.0.13</Version>
<AssemblyVersion>6.0.13.0</AssemblyVersion>
<RepositoryUrl>https://github.com/contentful/contentful.net</RepositoryUrl>
<FileVersion>6.0.12.0</FileVersion>
<FileVersion>6.0.13.0</FileVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DocumentationFile>bin\Release\netstandard1.5\Contentful.AspNetCore.xml</DocumentationFile>
Expand All @@ -25,7 +25,7 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="contentful.csharp" Version="6.0.12" />
<PackageReference Include="contentful.csharp" Version="6.0.13" />
<PackageReference Include="gitlink" Version="3.1.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
Expand Down
21 changes: 21 additions & 0 deletions Contentful.Core.Tests/Models/Rendering/HtmlRenderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IContent>(),
Data = new AssetStructureData
{
Target = new Asset()
},
NodeType = ""
};

//Act
var html = renderer.Render(assetStructure);
//Assert
Assert.Equal("<a></a>", html);
}
}
}
6 changes: 3 additions & 3 deletions Contentful.Core/Contentful.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute>
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute>
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute>
<AssemblyVersion>6.0.12.0</AssemblyVersion>
<FileVersion>6.0.12.0</FileVersion>
<Version>6.0.12</Version>
<AssemblyVersion>6.0.13.0</AssemblyVersion>
<FileVersion>6.0.13.0</FileVersion>
<Version>6.0.13</Version>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="gitlink" Version="3.1.0">
Expand Down
3 changes: 2 additions & 1 deletion Contentful.Core/Models/Authoring.cs
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,8 @@ public string Render(IContent content)
sb.Append($"<img src=\"{asset.File.Url}\" alt=\"{asset.Title}\" />");
}else
{
sb.Append($"<a href=\"{asset.File.Url}\">");
var url = asset.File?.Url;
sb.Append(string.IsNullOrEmpty(url)? "<a>" : $"<a href=\"{asset.File.Url}\">");

if (assetStructure.Content != null && assetStructure.Content.Any())
{
Expand Down

0 comments on commit ff1e679

Please sign in to comment.