Fluid icon indicating copy to clipboard operation
Fluid copied to clipboard

[FEATURE] Allow null coalesce operator in evaluation (#522)

Open CDRO opened this issue 4 years ago • 6 comments

CDRO avatar Oct 26 '21 14:10 CDRO

I would strongly urge to not support quoted strings because aribrary strings within inline syntax has a very high risk of breaking the parsing engine in v2. While we can support simple strings, inviting people to use syntax which contains odd characters or even nested Fluid code will inevitably lead to some nasty edge cases or unpredictable parsing.

Even for v3 I would not invite such usage, although unexpected parsing behavior is much less of an issue on that version.

NamelessCoder avatar Oct 28 '21 13:10 NamelessCoder

I would strongly urge to not support quoted strings because aribrary strings within inline syntax has a very high risk of breaking the parsing engine in v2. While we can support simple strings, inviting people to use syntax which contains odd characters or even nested Fluid code will inevitably lead to some nasty edge cases or unpredictable parsing.

Ok, so only this syntax should be allowed?

<span>{ model.field ?? Default }</span>

Or would you just keep one of two possible string quotations? Is the parser able to recognize something like this?

<span>{ model.field ?? Sorry, this value has not been set. }</span>

CDRO avatar Oct 28 '21 14:10 CDRO

No, what I mean is we shouldn't allow arbitrary strings at all - quoted or otherwise. Basically, treat everything as a variable. The problem is that the parser (v2, being regexp-based) is only able to recognize a very specific set of characters as part of an inline expression and arbitrary strings have a very high likelihood of containing something that causes the expression to not be detected as Fluid at all.

We could make an exception that allows using hardcoded numeric values since they don't carry a risk of breaking the detection patterns, though.

NamelessCoder avatar Oct 28 '21 14:10 NamelessCoder

No, what I mean is we shouldn't allow arbitrary strings at all - quoted or otherwise. Basically, treat everything as a variable. The problem is that the parser (v2, being regexp-based) is only able to recognize a very specific set of characters as part of an inline expression and arbitrary strings have a very high likelihood of containing something that causes the expression to not be detected as Fluid at all.

Got it, so if I want to have a string as fallback, I'd proceed something like this:

<f:variable name="default" value="This is my default value" />
<span>{model.field ?? default }<span>

That sounds very good to me, I'll try to think about it when documenting this feature.

CDRO avatar Oct 28 '21 15:10 CDRO