Skip to content

Commit

Permalink
Escape unicode newlines when compiling
Browse files Browse the repository at this point in the history
Resolves #126, resolves #736.
  • Loading branch information
TheDancingCode committed Jul 12, 2018
1 parent 9a0ce36 commit 4d4dc40
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 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)
-------------------

Expand Down
1 change: 1 addition & 0 deletions nunjucks/src/compiler.js
Expand Up @@ -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');
Expand Down
5 changes: 5 additions & 0 deletions tests/compiler.js
Expand Up @@ -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 }}',
{
Expand Down

0 comments on commit 4d4dc40

Please sign in to comment.