Supporting patterns would open up a lot of possibilities, such as:
[BODY].url == *example.com/images/*
One of the challenges is detecting what's a pattern and what isn't.
To some extent, yes, *
could be escaped, but due to the way conditions are resolved, when both sides of the equation are compared, they're already resolved, this could cause problems.
For instance, let's say you have the following condition:
[BODY].comment == *butterfl*
When it would be resolved, it would then become the following, assuming [BODY].comment
is "I love butterflies":
I love butterflies == *butterfl* // condition passes
At this point, we can easily detect which one is the pattern and which one isn't, but what if [BODY].comment
contains a *
?:
f*** this == *butterfl* // condition fails
So what, do we compare two patterns? That's weird.
Now let's pretend that the condition doesn't actually contain a pattern, but the resolved placeholder does:
and let's assume [BODY].name
is resolved to *
:
* == john.doe // condition passes
So now you'd have placeholders potentially triggered a pattern check for no reason.
The suggestion
Just like the length function (len()
, i.e. len([BODY].name)
), a pattern function could be introduced:
[BODY].comment == pattern(*butterfl*)
is resolved to
I love butterflies == pattern(*butterfl*) // condition passes
and
assuming [BODY].name
is resolved to *
, would give this:
* == john.doe // condition fails
which would fail because *
isn't wrapped by pattern(
and )
You could however make the placeholder value a pattern, if you wanted:
pattern([BODY].name) == john.doe
pattern(*) == john.doe // condition passes
Caveat
Readability is important, but so is consistency.
The length function is len(...)
- a shorter version of length(...)
.
So for the sake of consistency, the pattern function should be pat(...)
, a shorter version of pattern(...)
.
I originally wanted to call it pattern
despite the reasoning above, but after further consideration, since the string resolved will contain one or multiple asterisk (i.e. pat(blabla*)
), it should be clear enough.
Here's an example:
Condition:
Result:
I believe that by default, the pat(10.*)
is self-explanatory.