valyala / fasttemplate

Simple and fast template engine for Go
MIT License
846 stars 81 forks source link

make ExecuteStringStd to be compatible to strings.Replacer on nested tags #24

Open DoubleDi opened 3 years ago

DoubleDi commented 3 years ago

Hi @valyala! In #23 we added ExecuteStringStd which works as a drop-in replacement to strings.Replacer. It worked great, but we found a missmatch on nested start/end tags. Here is an example:

{"x":"{id}"} 

After replacing id with strings.Replacer:

{"x":"1"} 

After replacing id with fasttemplate.ExecuteStringStd:

{"x":"{id}"}

The reason is because fasttemplate takes the first start tag it finds, but strings.Replacer takes the closest to the end tag. So i made a PR to change the logic only in the ExecuteStringStd and other *Std funcs to make them compatible with strings.Replacer.

Please review when you have the time