From e50b10132f490b736f2bf23c36d58ba8b2a7809f Mon Sep 17 00:00:00 2001 From: ema Date: Fri, 24 Apr 2026 02:43:44 +0800 Subject: [PATCH] Improve extension parsing and add balcklist for .insv #1802 --- QuickLook/Helpers/ExtensionFilterHelper.cs | 47 +++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/QuickLook/Helpers/ExtensionFilterHelper.cs b/QuickLook/Helpers/ExtensionFilterHelper.cs index 1e486a1..c703333 100644 --- a/QuickLook/Helpers/ExtensionFilterHelper.cs +++ b/QuickLook/Helpers/ExtensionFilterHelper.cs @@ -44,6 +44,13 @@ public static class ExtensionFilterHelper private const string UseAllowlistModeKey = "UseExtensionAllowlist"; private static readonly char[] ExtensionSeparators = [';', ',']; + private static readonly HashSet DefaultBlocklist = new(StringComparer.OrdinalIgnoreCase) + { + ".insv" + }; + + private static readonly HashSet DefaultAllowlist = new(StringComparer.OrdinalIgnoreCase); + private static HashSet _allowlistCache; private static HashSet _blocklistCache; private static bool? _useAllowlistModeCache; @@ -79,6 +86,7 @@ public static class ExtensionFilterHelper { var list = SettingHelper.Get(AllowlistKey, string.Empty); _allowlistCache = ParseExtensionList(list); + _allowlistCache.UnionWith(DefaultAllowlist); } return _allowlistCache; } @@ -96,6 +104,7 @@ public static class ExtensionFilterHelper { var list = SettingHelper.Get(BlocklistKey, string.Empty); _blocklistCache = ParseExtensionList(list); + _blocklistCache.UnionWith(DefaultBlocklist); } return _blocklistCache; } @@ -188,10 +197,46 @@ public static class ExtensionFilterHelper if (string.IsNullOrWhiteSpace(ext)) return null; - ext = ext.Trim().ToLowerInvariant(); + ext = ext.Trim(); + + if (IsPlaceholderToken(ext)) + return null; + + ext = ext.ToLowerInvariant(); if (!ext.StartsWith(".")) ext = "." + ext; + if (!IsValidExtension(ext)) + return null; + return ext; } + + private static bool IsPlaceholderToken(string token) + { + // $(ExtensionAllowlist), $(ExtensionBlocklist) or similar tokens are placeholders + token = token.Trim(); + return token.StartsWith("$(", StringComparison.Ordinal) && token.EndsWith(")", StringComparison.Ordinal); + } + + private static bool IsValidExtension(string ext) + { + if (string.IsNullOrWhiteSpace(ext)) + return false; + + if (!ext.StartsWith(".")) + return false; + + var extension = ext.Substring(1); + if (extension.Length == 0) + return false; + + foreach (var c in extension) + { + if (!char.IsLetterOrDigit(c) && c != '_' && c != '-') + return false; + } + + return true; + } }