Endless loop fix

when template contains some unclosed curly braces, there is an endless loop happened.
such as this code `<pre>{{{{content}}</pre>`