Fix breakage from truncation-mode PR

This commit is contained in:
mde
2015-11-26 11:00:18 -08:00
parent cb6aa372ef
commit b777b06d08
2 changed files with 9 additions and 5 deletions

View File

@@ -576,12 +576,16 @@ Template.prototype = {
function _addOutput() {
if (self.truncate) {
line = line
.replace(/\r?\n/, '')
// Only replace single leading linebreak in the line after
// -%> tag -- this is the single, trailing linebreak
// after the tag that the truncation mode replaces
// Handle Win / Unix / old Mac linebreaks -- do the \r\n
// combo first in the regex-or
line = line.replace(/^(?:\r\n|\r|\n)/, '')
self.truncate = false;
}
else if (self.opts.rmWhitespace) {
// Gotta me more careful here.
// Gotta be more careful here.
// .replace(/^(\s*)\n/, '$1') might be more appropriate here but as
// rmWhitespace already removes trailing spaces anyway so meh.
line = line.replace(/^\n/, '');

View File

@@ -519,7 +519,7 @@ suite('-%>', function () {
+ "<% }) -%>\n"
+ "</ul><% -%>\n";
var expectedResult = "<ul><li>geddy</li><li>neil</li><li>alex</li></ul>";
var expectedResult = "<ul><li>geddy</li>\n<li>neil</li>\n<li>alex</li>\n</ul>";
var fn;
fn = ejs.compile(content);
assert.equal(fn({users: users}),
@@ -533,7 +533,7 @@ suite('-%>', function () {
+ "<% }) -%>\r\n"
+ "</ul><% -%>\r\n";
var expectedResult = "<ul><li>geddy</li><li>neil</li><li>alex</li></ul>";
var expectedResult = "<ul><li>geddy</li>\r\n<li>neil</li>\r\n<li>alex</li>\r\n</ul>";
var fn;
fn = ejs.compile(content);
assert.equal(fn({users: users}),