feat(UriBuilderExtensions.AppendPath): Ermöglicht das sichere Hinzufügen neuer Pfade zu UriBuilders.

- Implementiert für Resolver
This commit is contained in:
tekh 2025-08-04 14:15:08 +02:00
parent 581bd22c24
commit 6a04f36388
3 changed files with 22 additions and 3 deletions

View File

@ -14,8 +14,11 @@ public class TfFileIconUriBuilderResolver : IValueResolver<TfFile, TfFileDto, Ur
public UriBuilder? Resolve(TfFile source, TfFileDto destination, UriBuilder? destMember, ResolutionContext context)
{
if(string.IsNullOrEmpty(source.Icon))
return null;
var builder = _uriBuilderFactory();
builder.Path = HttpUtility.UrlEncode(source.Icon);
builder.AppendPath(source.Icon);
return builder;
}
}

View File

@ -1,6 +1,5 @@
using AutoMapper;
using Microsoft.Extensions.Options;
using System.Web;
using WorkFlow.Application.Dto;
using WorkFlow.Domain.Entities;
@ -14,8 +13,11 @@ public class TfFileUriBuilderResolver : IValueResolver<TfFile, TfFileDto, UriBui
public UriBuilder? Resolve(TfFile source, TfFileDto destination, UriBuilder? destMember, ResolutionContext context)
{
if (string.IsNullOrEmpty(source.Path))
return null;
var builder = _uriBuilderFactory();
builder.Path = HttpUtility.UrlEncode(source.Path);
builder.AppendPath(source.Path);
return builder;
}
}

View File

@ -0,0 +1,14 @@
using System.Web;
namespace WorkFlow.Application.Mapping;
internal static class UriBuilderExtensions
{
public static void AppendPath(this UriBuilder uriBuilder, string path, bool encode = true)
{
if(encode)
path = HttpUtility.UrlEncode(path);
uriBuilder.Path = $"{uriBuilder.Path.TrimEnd('/', '\\')}/{path.Trim('/', '\\')}";
}
}