Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape unicode newlines when compiling #1126

Merged
merged 1 commit into from Sep 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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