Skip to content

Commit

Permalink
refactor: just reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Ftm-Sayadzadeh committed Aug 27, 2024
1 parent d64486c commit accab78
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions mohaymen-codestar-Team02/Middlewares/SanitizationMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public async Task InvokeAsync(HttpContext context)
var buffer = Encoding.UTF8.GetBytes(sanitizedBody);

context.Request.Body = new MemoryStream(buffer);
context.Request.Body.Position = 0;
context.Request.Body.Position = 0;
}
}
}
Expand All @@ -48,9 +48,11 @@ public async Task InvokeAsync(HttpContext context)
if (actionDescriptor != null)
{
var parameters = actionDescriptor.Parameters;
var dtoParameter = parameters.FirstOrDefault(p => p.ParameterType.IsClass && p.ParameterType != typeof(string));
var dtoParameter =
parameters.FirstOrDefault(p => p.ParameterType.IsClass && p.ParameterType != typeof(string));
return dtoParameter?.ParameterType;
}

return null;
}

Expand Down Expand Up @@ -78,18 +80,15 @@ private IEnumerable<string> SanitizeEnumerable(IEnumerable<string> dto)

private object SanitizeDto(object dto)
{
var properties = dto.GetType().GetProperties().Where(p => p.PropertyType == typeof(string) && p.CanWrite && p.CanRead);
var properties = dto.GetType().GetProperties()
.Where(p => p.PropertyType == typeof(string) && p.CanWrite && p.CanRead);

foreach (var property in properties)
{
var value = (string)property.GetValue(dto);
if (value != null)
{
property.SetValue(dto, _sanitizer.Sanitize(value));
}
if (value != null) property.SetValue(dto, _sanitizer.Sanitize(value));
}

return dto;
return dto;
}
}

}

0 comments on commit accab78

Please sign in to comment.