fixed matching of first property

This commit is contained in:
Jo-Be-Co
2026-04-14 02:48:03 +02:00
parent c1b8cc894a
commit c72e5a3568
2 changed files with 7 additions and 4 deletions

View File

@@ -156,11 +156,14 @@ public partial class ConditionalTagCollection<TClass>(bool caseSensitive = true)
^<(?<not>!)? # tags start with a '<'. Condtionals allow an optional ! captured in <not> to negate the condition
{TagNameForRegex()} # next the tagname needs to be matched with space being made optional. Also escape all '#'
\s+ # Separate the following with whitespace
(?<property>(?: # capture the <property>
(?<property> # capture the <property>
'(?:[^']|'')*' # - allow 'string' to be included in the format, with '' being an escaped ' character
| "(?:[^"]|"")*" # - allow "string" to be included in the format, with "" being an escaped " character
| [^:\#!=~<>&̸-] # - match any character with some exclusions that should only be used in operands
) +? (?<!\s)) # - don't let <property> end with a whitepace. Otherwise "<tagname = tag2->" would be matchable.
| (?: \[ (?: \\. # - properties may have optional formatting details enclosed in '[' and ']'. '\' escapes allways the next character
| [^\\\]] # unescaped characters except ']' and '\' are allowed in the formatting details
)* \] # closing the formatting details part
| . )+? # - match any character to form the property name. Capture non greedy so it won't match the operator part.
(?<!\s)) # - don't let <property> end with a whitepace. Otherwise "<tagname = tag2->" would be matchable.
\s+ # Separate the following operand with whitespace
(?<check_or_op> # capture operator in <op> and <num_op> with every char escapable
[\#!≡=≠~<>≤≥&∉∌∈∌⋂⊆⊇⊂⊃-]+ # allow a wide range of operators, all non alphanumeric

View File

@@ -639,7 +639,7 @@ namespace TemplatesTests
[DataRow("<cmp author != 'Sherlock'->true<-cmp>", "true")]
[DataRow("<!cmp author != 'Sherlock'->false<-cmp>", "")]
[DataRow("<cmp tag = 'Tag1'->true<-cmp>", "true")]
[DataRow("<cmp tag[separator(:)slice(-2..)] = 'Tag2:Tag3'->true<-cmp>", "true")]
[DataRow("<cmp tag[separator( : )slice(-2..)] = 'Tag2 : Tag3'->true<-cmp>", "true")]
[DataRow("<cmp audible subtitle[3] = 'an'->true<-cmp>", "")]
[DataRow("<cmp audible subtitle[3] = 'an '->true<-cmp>", "true")]
[DataRow("<cmp audible subtitle[3] = ' an'->true<-cmp>", "")]