Skip to content

Commit

Permalink
Merge pull request #185 from drwrf/bug/2028-and-2029
Browse files Browse the repository at this point in the history
Properly escape \u2028 and \u2029.
  • Loading branch information
sayrer committed Jun 16, 2014
2 parents d400e2f + 3319a8c commit 41c76fa
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
rQuot = /\"/g,
rNewline = /\n/g,
rCr = /\r/g,
rSlash = /\\/g;
rSlash = /\\/g,
rLineSep = /\u2028/,
rParagraphSep = /\u2029/;

Hogan.tags = {
'#': 1, '^': 2, '<': 3, '$': 4,
Expand Down Expand Up @@ -307,7 +309,9 @@
return s.replace(rSlash, '\\\\')
.replace(rQuot, '\\\"')
.replace(rNewline, '\\n')
.replace(rCr, '\\r');
.replace(rCr, '\\r')
.replace(rLineSep, '\\u2028')
.replace(rParagraphSep, '\\u2029');
}

function chooseMethod(s) {
Expand Down
16 changes: 16 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,22 @@ test("Escaping", function() {
}
});

test("Escaping \\u2028", function() {
var text = "{{foo}}\u2028{{bar}}";
var t = Hogan.compile(text);
var s = t.render({foo: 'foo', bar: 'bar'});

is(s, "foo\u2028bar", "\\u2028 improperly escaped");
});

test("Escaping \\u2029", function() {
var text = "{{foo}}\u2029{{bar}}";
var t = Hogan.compile(text);
var s = t.render({foo: 'foo', bar: 'bar'});

is(s, "foo\u2029bar", "\\u2029 improperly escaped");
});

test("Mustache Injection", function() {
var text = "{{foo}}";
var t = Hogan.compile(text);
Expand Down

0 comments on commit 41c76fa

Please sign in to comment.