From 8dbb5300d6ebd215e1cfed1f971a68f28f16b34c Mon Sep 17 00:00:00 2001 From: n00mkrad <61149547+n00mkrad@users.noreply.github.com> Date: Thu, 14 May 2026 01:40:22 +0200 Subject: [PATCH] Fix PseudoHash being able to generate invalid filenames --- CodeLegacy/Data/PseudoHash.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/CodeLegacy/Data/PseudoHash.cs b/CodeLegacy/Data/PseudoHash.cs index c45b0f6..68710be 100644 --- a/CodeLegacy/Data/PseudoHash.cs +++ b/CodeLegacy/Data/PseudoHash.cs @@ -11,18 +11,26 @@ namespace Flowframes.Data public static string GetHash(string path, bool b64 = true) { bool isDir = Directory.Exists(path); + string hash = ""; if (isDir) { var dir = new DirectoryInfo(path); var files = IoUtils.GetFileInfosSorted(path); - string dirHash = $"{dir.Name}{files.Sum(f => f.Length)}{dir.LastWriteTime.ToString("yyyyMMddHHmmss")}"; - return b64 ? Convert.ToBase64String(Encoding.UTF8.GetBytes(dirHash)).TrimEnd('=') : dirHash; + hash = $"{dir.Name}{files.Sum(f => f.Length)}{dir.LastWriteTime.ToString("yyyyMMddHHmmss")}"; + } + else + { + var file = new FileInfo(path); + hash = $"{file.Name}{file.Length}{file.LastWriteTime.ToString("yyyyMMddHHmmss")}"; } - var file = new FileInfo(path); - string hash = $"{file.Name}{file.Length}{file.LastWriteTime.ToString("yyyyMMddHHmmss")}"; - return b64 ? Convert.ToBase64String(Encoding.UTF8.GetBytes(hash)).TrimEnd('=') : hash; + if (!b64) + return hash; + + string hashB64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(hash)); + hashB64 = new string(hashB64.TrimEnd('=').Where(c => !Path.GetInvalidFileNameChars().Contains(c)).ToArray()); // Ensure no invalid chars in b64 hash + return hashB64; } } }