ultraq / thymeleafjs

A basic implementation of the Thymeleaf templating engine in JavaScript
Apache License 2.0
52 stars 8 forks source link

IfThenElseCondition can't parse empty string outputs #46

Closed abousta closed 2 years ago

abousta commented 2 years ago

Hi,

As it is my first report, I would like to thank you first for this very well coded and helpful project.

The expression processor seems to fail parsing a ternary condition that could output an empty string.

Steps to reproduce this bug :

ultraq commented 2 years ago

Hi there, thanks for the bug report! I've reproduced the error with the steps you've provided (thank you for those steps too!), and was able to track the problem down to the 'string literals' rule:

https://github.com/ultraq/thymeleafjs/blob/8523a3545bc1e1a7fc94c348c1fbb2ba35da9833/source/standard/expressions/ThymeleafExpressionLanguage.js#L259-L266

Looks like I'm attempting to do some regex trick which won't work with empty strings. I'll have to figure out what I'm trying to do there and see how to make it work with empty strings 🤔

abousta commented 2 years ago

Maybe you could try '^$|.*?(?!\\').'

That would mean something like

abousta commented 2 years ago

Sorry... I wrote too soon. My previous regex doesn't fail if you miss the first or last quote (I hate regex :)) )

But I think this one should work: ''|'.*?(?!\\').' , don't you ?

ultraq commented 2 years ago

I tried a few other things, but the fix ended up being pretty much what you've suggested, so thank you for that 👍 I'll push a release out with this fix in it soon.