Skip to content

Commit

Permalink
Properly escape \u2028 and \u2029.
Browse files Browse the repository at this point in the history
Javascript will treat these characters as new lines when parsing
code which can result in a syntax error.
  • Loading branch information
drwrf authored and Jonathan Geiger committed Jun 10, 2014
1 parent e2cc18e commit 5b0a314
Showing 1 changed file with 6 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

0 comments on commit 5b0a314

Please sign in to comment.