Skip to content

Commit

Permalink
Merge pull request #1126 from TheDancingCode/issue-126
Browse files Browse the repository at this point in the history
Escape unicode newlines when compiling
  • Loading branch information
fdintino committed Sep 4, 2018
2 parents 9a0ce36 + 4d4dc40 commit 39bb716
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 39bb716

Please sign in to comment.