Enhanced id validation, made url building more robust

This commit is contained in:
2024-11-10 16:43:56 +01:00
parent 42455e596b
commit e561ad8ee7
3 changed files with 31 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ namespace AMWD.Net.Api.Cloudflare
/// </summary>
public static class StringExtensions
{
private static readonly Regex _idCheckRegex = new(@"^[0-9a-f]{32}$", RegexOptions.Compiled);
private static readonly Regex _emailCheckRegex = new(@"^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$", RegexOptions.Compiled);
/// <summary>
@@ -26,6 +27,13 @@ namespace AMWD.Net.Api.Cloudflare
if (id.Length > 32)
throw new ArgumentOutOfRangeException(nameof(id));
if (!_idCheckRegex.IsMatch(id))
throw new ArgumentException("Invalid Cloudflare ID", nameof(id));
// TODO: It seems like Cloudflare IDs are GUIDs - should be verified.
//if (!Guid.TryParse(id, out _))
// throw new ArgumentException("Invalid Cloudflare ID", nameof(id));
}
/// <summary>