diff --git a/CHANGELOG.md b/CHANGELOG.md index 3daec305..d6468ed2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ Changelog ========= +* Fix "Unexpected token" error for U+2028 unicode newline. Fixes [#126](https://github.com/mozilla/nunjucks/issues/126) and [#736](https://github.com/mozilla/nunjucks/issues/736) + 3.1.3 (May 19 2018) ------------------- diff --git a/nunjucks/src/compiler.js b/nunjucks/src/compiler.js index 6c000fe7..6ef3c149 100644 --- a/nunjucks/src/compiler.js +++ b/nunjucks/src/compiler.js @@ -278,6 +278,7 @@ class Compiler extends Obj { val = val.replace(/\n/g, '\\n'); val = val.replace(/\r/g, '\\r'); val = val.replace(/\t/g, '\\t'); + val = val.replace(/\u2028/g, '\\u2028'); this._emit(`"${val}"`); } else if (node.value === null) { this._emit('null'); diff --git a/tests/compiler.js b/tests/compiler.js index 4c3fbaa8..d6b590d9 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -55,6 +55,11 @@ finish(done); }); + it('should escape Unicode line seperators', function(done) { + equal('\u2028', '\u2028'); + finish(done); + }); + it('should compile references', function(done) { equal('{{ foo.bar }}', {