Improved the rules for provider names

This commit is contained in:
Thorsten Sommer 2024-09-08 16:45:16 +02:00
parent 30235b19eb
commit c6551a63df
Signed by: tsommer
GPG Key ID: 371BBA77A02C0108
2 changed files with 5 additions and 32 deletions

View File

@ -1,5 +1,3 @@
using System.Text.RegularExpressions;
using AIStudio.Provider;
using AIStudio.Settings;
@ -245,40 +243,14 @@ public partial class ProviderDialog : ComponentBase
return null;
}
[GeneratedRegex(@"^[a-zA-Z0-9\-_. ]+$")]
private static partial Regex InstanceNameRegex();
private static readonly string[] RESERVED_NAMES = ["CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9"];
private string? ValidatingInstanceName(string instanceName)
{
if (string.IsNullOrWhiteSpace(instanceName))
return "Please enter an instance name.";
if (instanceName.StartsWith(' ') || instanceName.StartsWith('.'))
return "The instance name must not start with a space or a dot.";
if (instanceName.EndsWith(' ') || instanceName.EndsWith('.'))
return "The instance name must not end with a space or a dot.";
if (instanceName.StartsWith('-') || instanceName.StartsWith('_'))
return "The instance name must not start with a hyphen or an underscore.";
if (instanceName.Length > 255)
return "The instance name must not exceed 255 characters.";
if (!InstanceNameRegex().IsMatch(instanceName))
return "The instance name must only contain letters, numbers, spaces, hyphens, underscores, and dots.";
if (instanceName.Contains(" "))
return "The instance name must not contain consecutive spaces.";
if (RESERVED_NAMES.Contains(instanceName.ToUpperInvariant()))
return "This name is reserved and cannot be used.";
if (instanceName.Any(c => Path.GetInvalidFileNameChars().Contains(c)))
return "The instance name contains invalid characters.";
if (instanceName.Length > 40)
return "The instance name must not exceed 40 characters.";
// The instance name must be unique:
var lowerInstanceName = instanceName.ToLowerInvariant();

View File

@ -1,3 +1,4 @@
# v0.9.7, build 182 (2024-09-09 xx:xx UTC)
- Added an introductory description to the provider settings.
- Improved hyphenation for continuous text so that the rules of the respective language are taken into account where possible.
- Improved hyphenation for continuous text so that the rules of the respective language are taken into account where possible.
- Improved the rules for provider names: unnecessary restrictions from earlier versions have been removed. You can now use emojis in your provider names when you like.