From 8570237fb32820925c1e0c2b20f02b8b0303c505 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Mon, 2 Dec 2024 16:31:19 -0500 Subject: [PATCH] Disallow empty values in custom dictionaries --- BinaryObjectScanner/CheckDictionary.cs | 2 +- BinaryObjectScanner/ProtectionDictionary.cs | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/BinaryObjectScanner/CheckDictionary.cs b/BinaryObjectScanner/CheckDictionary.cs index 1093172b..84d1146d 100644 --- a/BinaryObjectScanner/CheckDictionary.cs +++ b/BinaryObjectScanner/CheckDictionary.cs @@ -13,7 +13,7 @@ namespace BinaryObjectScanner /// Handles the proper Add implementation public void Append(T key, string? value) { - if (value == null) + if (value == null || value.Trim().Length == 0) return; #if NET20 || NET35 diff --git a/BinaryObjectScanner/ProtectionDictionary.cs b/BinaryObjectScanner/ProtectionDictionary.cs index 00761575..d5b16ad2 100644 --- a/BinaryObjectScanner/ProtectionDictionary.cs +++ b/BinaryObjectScanner/ProtectionDictionary.cs @@ -24,7 +24,7 @@ namespace BinaryObjectScanner public void Append(string key, string value) { // If the value is empty, don't add it - if (string.IsNullOrEmpty(value)) + if (value == null || value.Trim().Length == 0) return; Append(key, [value]); @@ -44,6 +44,9 @@ namespace BinaryObjectScanner EnsureKey(key); foreach (string value in values) { + if (value == null || value.Trim().Length == 0) + continue; + this[key].Enqueue(value); } } @@ -180,6 +183,9 @@ namespace BinaryObjectScanner foreach (string value in values) { + if (value == null || value.Trim().Length == 0) + continue; + this[key].Enqueue(value); } }