Ensure template delimiters are tokenized correctly. [closes #64]

Former-commit-id: 814f3f8a840a70a9b455e5f91da0e21174f08787
This commit is contained in:
John-David Dalton
2012-08-31 13:50:10 -07:00
parent 83356142c1
commit 2b0bffc362
2 changed files with 11 additions and 5 deletions

View File

@@ -78,7 +78,7 @@
);
/** Used to match internally used tokens in template text */
var reToken = /__token__(\d+)/g;
var reToken = /__token(\d+)__/g;
/** Used to match HTML characters */
var reUnescapedHtml = /[&<>"']/g;
@@ -96,7 +96,8 @@
var templateCounter = 0;
/** Used to replace template delimiters */
var token = '__token__';
var tokenHead = '__token',
tokenFoot = '__';
/** Used to store tokenized template text snippets */
var tokenized = [];
@@ -840,7 +841,7 @@
}
var index = tokenized.length;
tokenized[index] = "' +\n__e(" + value + ") +\n'";
return token + index;
return tokenHead + index + tokenFoot;
}
/**
@@ -858,7 +859,7 @@
if (evaluateValue) {
var index = tokenized.length;
tokenized[index] = "';\n" + evaluateValue + ";\n__p += '";
return token + index;
return tokenHead + index + tokenFoot;
}
return escapeValue
? tokenizeEscape(null, escapeValue)
@@ -879,7 +880,7 @@
}
var index = tokenized.length;
tokenized[index] = "' +\n((__t = (" + value + ")) == null ? '' : __t) +\n'";
return token + index;
return tokenHead + index + tokenFoot;
}
/**

View File

@@ -1487,6 +1487,11 @@
}
ok(pass);
});
test('should tokenize delimiters correctly', function() {
var compiled = _.template('<span class="icon-<%= type %>2"></span>');
equal(compiled({ 'type': 1 }), '<span class="icon-12"></span>');
});
}());
/*--------------------------------------------------------------------------*/