From e4e7191d8ddf6afd3d806b1af80c0be7e96a923d Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 21 Jun 2023 10:37:48 +0200 Subject: [PATCH] Include control characters in TextInput FileNames and PathNames rules --- CHANGELOG.md | 1 + MLEM/Input/TextInput.cs | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f416d60..92fdda8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ Improvements - Allow changing the default values used by default TextFormatter codes - Allow setting ExternalGestureHandling through the InputHandler constructor - Allow specifying start and end indices when drawing a TokenizedString +- Include control characters in TextInput FileNames and PathNames rules Fixes - Fixed control characters being included in TextInput diff --git a/MLEM/Input/TextInput.cs b/MLEM/Input/TextInput.cs index 8095d5a..f91fc87 100644 --- a/MLEM/Input/TextInput.cs +++ b/MLEM/Input/TextInput.cs @@ -61,11 +61,23 @@ namespace MLEM.Input { /// /// A that only allows characters not contained in /// - public static readonly Rule PathNames = (input, add) => add.IndexOfAny(Path.GetInvalidPathChars()) < 0; + public static readonly Rule PathNames = (input, add) => { + foreach (var c in add) { + if (char.IsControl(c) || Path.GetInvalidPathChars().Contains(c)) + return false; + } + return true; + }; /// /// A that only allows characters not contained in /// - public static readonly Rule FileNames = (input, add) => add.IndexOfAny(Path.GetInvalidFileNameChars()) < 0; + public static readonly Rule FileNames = (input, add) => { + foreach (var c in add) { + if (char.IsControl(c) || Path.GetInvalidFileNameChars().Contains(c)) + return false; + } + return true; + }; /// /// This text input's current text