diff --git a/nunjucks/src/filters.js b/nunjucks/src/filters.js index 8e17f784..1a99c1e1 100644 --- a/nunjucks/src/filters.js +++ b/nunjucks/src/filters.js @@ -182,8 +182,8 @@ function indent(str, width, indentfirst) { const sp = lib.repeat(' ', width); const res = lines.map((l, i) => { - return (i === 0 && !indentfirst) ? `${l}\n` : `${sp}${l}\n`; - }).join(''); + return (i === 0 && !indentfirst) ? l : `${sp}${l}`; + }).join('\n'); return r.copySafeness(str, res); } diff --git a/tests/filters.js b/tests/filters.js index 6d526d30..2c56bc7c 100644 --- a/tests/filters.js +++ b/tests/filters.js @@ -405,15 +405,15 @@ it('indent', function(done) { equal('{{ "one\ntwo\nthree" | indent }}', - 'one\n two\n three\n'); + 'one\n two\n three'); equal('{{ "one\ntwo\nthree" | indent(2) }}', - 'one\n two\n three\n'); + 'one\n two\n three'); equal('{{ "one\ntwo\nthree" | indent(2, true) }}', - ' one\n two\n three\n'); + ' one\n two\n three'); equal('{{ str | indent }}', { str: r.markSafe('one\ntwo\nthree') - }, 'one\n two\n three\n'); + }, 'one\n two\n three'); equal('{{ "" | indent }}', ''); equal('{{ undefined | indent }}', '');