feat(UriBuilderExtensions.AppendPath): Ermöglicht das sichere Hinzufügen neuer Pfade zu UriBuilders.
- Implementiert für Resolver
This commit is contained in:
parent
581bd22c24
commit
6a04f36388
@ -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;
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
14
src/WorkFlow.Application/Mapping/UriBuilderExtensions.cs
Normal file
14
src/WorkFlow.Application/Mapping/UriBuilderExtensions.cs
Normal 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('/', '\\')}";
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user