Permalink
Browse files

don't assume that the open and close tags are going to be 2 chars

  • Loading branch information...
1 parent 8ba1f0d commit cccbf8b3fc6213c5f07b547c3a86cd447cfe5856 Ashley Dev committed Aug 6, 2010
Showing with 24 additions and 3 deletions.
  1. +3 −0 .gitignore
  2. +3 −3 lib/ejs.js
  3. +18 −0 test/ejs.test.js
View
@@ -0,0 +1,3 @@
+# ignore any vim files:
+*.sw[a-z]
+vim/.netrwhist
View
@@ -71,8 +71,8 @@ var parse = exports.parse = function(str, options){
];
for (var i = 0, len = str.length; i < len; ++i) {
- if (str[i] == open[0] && str[i+1] == open[1] ) {
- i += 2
+ if (str.slice(i, open.length + i) == open) {
+ i += open.length
var prefix, postfix;
if (str[i] == '=') {
@@ -91,7 +91,7 @@ var parse = exports.parse = function(str, options){
var start = i;
var end = str.indexOf(close, i);
buf.push(prefix, str.slice(i, end), postfix);
- i += end - start + 1;
+ i += end - start + close.length - 1;
} else if (str[i] == "\\") {
buf.push("\\\\");
View
@@ -124,6 +124,24 @@ module.exports = {
close: '?>'
}));
},
+
+ 'test custom tags over 2 chars': function(assert){
+ var html = '<p>foo</p>',
+ str = '<p>{{{{= "foo" }>>}</p>';
+
+ assert.equal(html, ejs.render(str, {
+ open: '{{{{',
+ close: '}>>}'
+ }));
+
+ var html = '<p>foo</p>',
+ str = '<p><??= "foo" ??></p>';
+
+ assert.equal(html, ejs.render(str, {
+ open: '<??',
+ close: '??>'
+ }));
+ },
'test global custom tags': function(assert){
var html = '<p>foo</p>',

0 comments on commit cccbf8b

Please sign in to comment.