Skip to content

Commit

Permalink
Made alias repository case insensitive. Fixes #2087
Browse files Browse the repository at this point in the history
  • Loading branch information
tidyui committed Jan 3, 2025
1 parent 8aa4c29 commit 30b96e2
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion core/Piranha/Services/Internal/AliasService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public async Task<Alias> GetByAliasUrlAsync(string url, Guid? siteId = null)

if (aliasUrls != null)
{
var aliasUrl = aliasUrls.FirstOrDefault(x => x.AliasUrl == url);
var aliasUrl = aliasUrls.FirstOrDefault(x => x.AliasUrl.Equals(url, StringComparison.InvariantCultureIgnoreCase));

if (aliasUrl != null)
{
Expand Down
4 changes: 2 additions & 2 deletions data/Piranha.Data.EF/Repositories/AliasRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public Task<Alias> GetByAliasUrl(string url, Guid siteId)
{
return _db.Aliases
.AsNoTracking()
.Where(a => a.SiteId == siteId && a.AliasUrl == url)
.Where(a => a.SiteId == siteId && a.AliasUrl.ToLower() == url.ToLower())
.Select(a => new Alias
{
Id = a.Id,
Expand All @@ -109,7 +109,7 @@ public async Task<IEnumerable<Alias>> GetByRedirectUrl(string url, Guid siteId)
{
return await _db.Aliases
.AsNoTracking()
.Where(a => a.SiteId == siteId && a.RedirectUrl == url)
.Where(a => a.SiteId == siteId && a.RedirectUrl.ToLower() == url.ToLower())
.Select(a => new Alias
{
Id = a.Id,
Expand Down
24 changes: 24 additions & 0 deletions test/Piranha.Tests/Services/AliasTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,18 @@ public async Task GetByAliasUrl()
}
}

[Fact]
public async Task GetByAliasUrlWithDifferentCase()
{
using (var api = CreateApi())
{
var model = await api.Aliases.GetByAliasUrlAsync("/Old-URL");

Assert.NotNull(model);
Assert.Equal(ALIAS_1, model.AliasUrl);
}
}

[Fact]
public async Task GetByRedirectUrl()
{
Expand All @@ -222,6 +234,18 @@ public async Task GetByRedirectUrl()
}
}

[Fact]
public async Task GetByRedirectUrlWithDifferentCase()
{
using (var api = CreateApi())
{
var models = await api.Aliases.GetByRedirectUrlAsync("/ReDiRect-1");

Assert.Single(models);
Assert.Equal(ALIAS_1, models.First().AliasUrl);
}
}

[Fact]
public async Task Update()
{
Expand Down

0 comments on commit 30b96e2

Please sign in to comment.