mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-10 02:47:50 +00:00
Ensure template delimiters are tokenized correctly. [closes #64]
Former-commit-id: 814f3f8a840a70a9b455e5f91da0e21174f08787
This commit is contained in:
11
lodash.js
11
lodash.js
@@ -78,7 +78,7 @@
|
|||||||
);
|
);
|
||||||
|
|
||||||
/** Used to match internally used tokens in template text */
|
/** Used to match internally used tokens in template text */
|
||||||
var reToken = /__token__(\d+)/g;
|
var reToken = /__token(\d+)__/g;
|
||||||
|
|
||||||
/** Used to match HTML characters */
|
/** Used to match HTML characters */
|
||||||
var reUnescapedHtml = /[&<>"']/g;
|
var reUnescapedHtml = /[&<>"']/g;
|
||||||
@@ -96,7 +96,8 @@
|
|||||||
var templateCounter = 0;
|
var templateCounter = 0;
|
||||||
|
|
||||||
/** Used to replace template delimiters */
|
/** Used to replace template delimiters */
|
||||||
var token = '__token__';
|
var tokenHead = '__token',
|
||||||
|
tokenFoot = '__';
|
||||||
|
|
||||||
/** Used to store tokenized template text snippets */
|
/** Used to store tokenized template text snippets */
|
||||||
var tokenized = [];
|
var tokenized = [];
|
||||||
@@ -840,7 +841,7 @@
|
|||||||
}
|
}
|
||||||
var index = tokenized.length;
|
var index = tokenized.length;
|
||||||
tokenized[index] = "' +\n__e(" + value + ") +\n'";
|
tokenized[index] = "' +\n__e(" + value + ") +\n'";
|
||||||
return token + index;
|
return tokenHead + index + tokenFoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -858,7 +859,7 @@
|
|||||||
if (evaluateValue) {
|
if (evaluateValue) {
|
||||||
var index = tokenized.length;
|
var index = tokenized.length;
|
||||||
tokenized[index] = "';\n" + evaluateValue + ";\n__p += '";
|
tokenized[index] = "';\n" + evaluateValue + ";\n__p += '";
|
||||||
return token + index;
|
return tokenHead + index + tokenFoot;
|
||||||
}
|
}
|
||||||
return escapeValue
|
return escapeValue
|
||||||
? tokenizeEscape(null, escapeValue)
|
? tokenizeEscape(null, escapeValue)
|
||||||
@@ -879,7 +880,7 @@
|
|||||||
}
|
}
|
||||||
var index = tokenized.length;
|
var index = tokenized.length;
|
||||||
tokenized[index] = "' +\n((__t = (" + value + ")) == null ? '' : __t) +\n'";
|
tokenized[index] = "' +\n((__t = (" + value + ")) == null ? '' : __t) +\n'";
|
||||||
return token + index;
|
return tokenHead + index + tokenFoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1487,6 +1487,11 @@
|
|||||||
}
|
}
|
||||||
ok(pass);
|
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>');
|
||||||
|
});
|
||||||
}());
|
}());
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|||||||
Reference in New Issue
Block a user