@@ -90,10 +90,28 @@ protected Mustache compile(final Reader reader, String tag, final AtomicInteger
9090 if (c == sm .charAt (0 )) {
9191 br .mark (1 );
9292 if (sm .length () == 1 || br .read () == sm .charAt (1 )) {
93+ // If it is a delimiter change we need to specially handle it
9394 // Two mustaches, now capture command
9495 StringBuilder sb = new StringBuilder ();
96+ br .mark (1 );
97+ c = br .read ();
98+ boolean delimiter = c == '=' ;
99+ if (delimiter ) {
100+ sb .append ((char ) c );
101+ } else {
102+ br .reset ();
103+ }
95104 while ((c = br .read ()) != -1 ) {
96105 br .mark (1 );
106+ if (delimiter ) {
107+ if (c == '=' ) {
108+ // Reached the end of the definition
109+ delimiter = false ;
110+ } else {
111+ sb .append ((char ) c );
112+ }
113+ continue ;
114+ }
97115 if (c == em .charAt (0 )) {
98116 if (em .length () > 1 ) {
99117 if (br .read () == em .charAt (1 )) {
@@ -209,14 +227,14 @@ protected Mustache compile(final Reader reader, String tag, final AtomicInteger
209227 case '=' :
210228 // Change delimiters
211229 out = write (mv , out , file , currentLine .intValue (), startOfLine );
212- String delimiters = command .replaceAll ( " \\ s+" , "" );
213- int length = delimiters . length ( );
214- if (length > 6 || length / 2 * 2 != length ) {
230+ String trimmed = command .substring ( 1 ). trim ( );
231+ String [] split = trimmed . split ( " \\ s+" );
232+ if (split . length != 2 ) {
215233 TemplateContext tc = new TemplateContext (sm , em , file , currentLine .get (), startOfLine );
216- throw new MustacheException ("Invalid delimiter string: " + delimiters , tc );
234+ throw new MustacheException ("Invalid delimiter string: " + trimmed , tc );
217235 }
218- sm = delimiters . substring ( 1 , length / 2 ) ;
219- em = delimiters . substring ( length / 2 , length - 1 ) ;
236+ sm = split [ 0 ] ;
237+ em = split [ 1 ] ;
220238 break ;
221239 default : {
222240 if (c == -1 ) {
0 commit comments