diff options
| author | Jake Mannens <jake@asger.xyz> | 2026-05-25 18:16:28 +1000 |
|---|---|---|
| committer | Jake Mannens <jake@asger.xyz> | 2026-05-25 23:47:24 +1000 |
| commit | 7b08cf42d6938fe91c72cf36504133e48001b3a2 (patch) | |
| tree | ea294da53d99f84e45d8e0064895f964dc7442a9 | |
| parent | 80c5935d9764794fd7c276ce2346339989c8647b (diff) | |
Added basic string sanitization to ApiMediaController
| -rw-r--r-- | Controllers/ApiMediaController.cs | 7 | ||||
| -rw-r--r-- | Util.cs | 5 |
2 files changed, 9 insertions, 3 deletions
diff --git a/Controllers/ApiMediaController.cs b/Controllers/ApiMediaController.cs index a1b07b1..58fd043 100644 --- a/Controllers/ApiMediaController.cs +++ b/Controllers/ApiMediaController.cs @@ -1,5 +1,6 @@ using HyperBooru.ApiModels; using HyperBooru.Services; +using HyperBooru.Util; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -54,8 +55,8 @@ public class ApiMediaController : Controller { if(media is null) return NotFound(); - media.ShortDescription = updatedMedia.ShortDescription; - media.LongDescription = updatedMedia.LongDescription; + media.ShortDescription = updatedMedia.ShortDescription.NullIfEmpty(); + media.LongDescription = updatedMedia.LongDescription.NullIfEmpty(); await db.SaveChangesAsync(); await transaction.CommitAsync(); @@ -87,7 +88,7 @@ public class ApiMediaController : Controller { metadata?.LastAccessTime, metadata?.LastWriteTime, metadata?.CreateTime, - metadata?.Path, + metadata?.Path.NullIfEmpty(), metadata?.PathType, metadata?.Tags); @@ -5,6 +5,11 @@ public static class Extensions { "K", "M", "G", "T", "P", "E", "Z", "Y", "R", "Q" }; + public static string? NullIfEmpty(this string s) { + s = s.Trim(); + return string.IsNullOrEmpty(s) ? null : s; + } + public static DateTime? TryParseDateTimeUtc(this string s) { bool success = DateTime.TryParse(s, out var dateTime); return success ? DateTime.SpecifyKind(dateTime, DateTimeKind.Utc) : null; |
