Skip to content

Commit 788f296

Browse files
committed
Should handle special characters for tags
1 parent b81a72c commit 788f296

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

LinkDotNet.Blog.IntegrationTests/Web/Pages/SearchByTagTests.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Threading.Tasks;
1+
using System;
2+
using System.Threading.Tasks;
23
using Bunit;
34
using FluentAssertions;
45
using LinkDotNet.Blog.TestUtilities;
@@ -26,6 +27,19 @@ public async Task ShouldOnlyDisplayTagsGivenByParameter()
2627
tags.Should().HaveCount(2);
2728
}
2829

30+
[Fact]
31+
public async Task ShouldHandleSpecialCharacters()
32+
{
33+
using var ctx = new TestContext();
34+
await AddBlogPostWithTagAsync("C#");
35+
ctx.Services.AddScoped<IRepository>(_ => BlogPostRepository);
36+
var cut = ctx.RenderComponent<SearchByTag>(p => p.Add(s => s.Tag, Uri.EscapeDataString("C#")));
37+
38+
var tags = cut.FindAll(".blog-card");
39+
40+
tags.Should().HaveCount(1);
41+
}
42+
2943
private async Task AddBlogPostWithTagAsync(string tag)
3044
{
3145
var blogPost = new BlogPostBuilder().WithTags(tag).Build();

LinkDotNet.Blog.Web/Pages/SearchByTag.razor

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
IList<BlogPost> _blogPosts = new List<BlogPost>();
1818
protected override async Task OnInitializedAsync()
1919
{
20+
Tag = Uri.UnescapeDataString(Tag);
2021
_blogPosts = (await _repository.GetAllAsync(b => b.Tags.Any(t => t.Content == Tag), b => b.UpdatedDate)).ToList();
2122
}
2223
}

LinkDotNet.Blog.Web/Shared/ShortBlogPost.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
@using LinkDotNet.Domain
2+
@using System.Net
3+
@using System.Web
24
@inject NavigationManager _navigationManager
35
@inherits MarkdownComponentBase
46
<div class="blog-card @AltCssClass">
@@ -12,7 +14,7 @@
1214
<ul>
1315
@foreach (var tag in BlogPost.Tags.Select(t => t.Content))
1416
{
15-
<li><a href="/searchByTag/@tag">@tag</a></li>
17+
<li><a href="/searchByTag/@(Uri.EscapeDataString(tag))">@tag</a></li>
1618
}
1719
</ul>
1820
</li>

0 commit comments

Comments
 (0)