From c5f0b720e6f4190aa682835cd4b0ed79a3daab5a Mon Sep 17 00:00:00 2001 From: Lilith River Date: Tue, 11 Jun 2024 21:55:49 -0600 Subject: [PATCH] Allow match condition names to include 0-9 if not the first char --- .../Matching/ExpressionParsingHelpers.cs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/Imazen.Routing/Matching/ExpressionParsingHelpers.cs b/src/Imazen.Routing/Matching/ExpressionParsingHelpers.cs index 9733d40..ce72ec0 100644 --- a/src/Imazen.Routing/Matching/ExpressionParsingHelpers.cs +++ b/src/Imazen.Routing/Matching/ExpressionParsingHelpers.cs @@ -139,11 +139,20 @@ internal static bool TryReadConditionName(ReadOnlySpan text, for (var i = 0; i < conditionNameEnds; i++) { var c = text[i]; - if (c != '_' && c != '-' && c is < 'a' or > 'z') + if (i == 0) { - error = $"Invalid character '{text[i]}' (a-z-_ only) in condition name. Condition expression: '{text.ToString()}'"; - return false; + if (c is >= 'a' and <= 'z') + { + continue; + } + } else if (c is >= 'a' and <= 'z' or >= '0' and <= '9' or '_' or '-') + { + continue; } + + error = $"Invalid character '{text[i]}' (a-z)(a-z0-9-_ only) in condition name. Condition expression: '{text.ToString()}'"; + return false; + } error = null; return true;