purpleidea / mgmt

Next generation distributed, event-driven, parallel config management!
https://purpleidea.com/tags/mgmtconfig/
GNU General Public License v3.0
3.64k stars 314 forks source link

lang: Improve string interpolation #635

Closed purpleidea closed 3 years ago

purpleidea commented 3 years ago

The original string interpolation was based on hil which didn't allow proper escaping, since they used a different escape pattern. Secondly, the golang Unquote function didn't deal with backslash escaping either.

This patch replaces both of these so that string interpolation works properly. This removes the ability to allow inline function calls in a string, however this was an incidental feature, and it's not clear that having it is a good idea.

There are still some small bugs or at least some uncertainties in what should be expected, but this is definitely due to my lack of experience with ragel, and should be easy to improve with a small patch and a test. In any case, this is much better than the original hil implementation.

purpleidea commented 3 years ago

@roidelapluie Sorry it took so long, but I have a fix for https://github.com/purpleidea/mgmt/issues/521 What's missing: I need you to please have a look and make sure I didn't get any behaviour wrong. If you have any test cases to add (you can look and see how simple it is to add one liners) please do! Also please check I did them all the way we want!

Thanks!

purpleidea commented 3 years ago

Merged a variant with comments address. Woo. There actually still is a subtle bug or two in the interpolation, but nothing too complex, and I think it can be easily fixed by someone who is experienced with ragel. Have a look at the mcl tests if interested. I wanted to get all the big plumbing in, so that future fixes are small. This is still a big improvement over the initial bad hil implementation!