Skip to content

Commit

Permalink
Escape unicode newlines in string literals
Browse files Browse the repository at this point in the history
Fixes #375
  • Loading branch information
kpdecker committed Apr 6, 2013
1 parent bee0fac commit 4d66d0c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 3 additions & 1 deletion dist/handlebars.js
Expand Up @@ -1971,7 +1971,9 @@ JavaScriptCompiler.prototype = {
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r') + '"';
.replace(/\r/g, '\\r')
.replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4
.replace(/\u2029/g, '\\u2029') + '"';
},

setupHelper: function(paramSize, name, missingParams) {
Expand Down
4 changes: 3 additions & 1 deletion lib/handlebars/compiler/compiler.js
Expand Up @@ -1130,7 +1130,9 @@ JavaScriptCompiler.prototype = {
.replace(/\\/g, '\\\\')
.replace(/"/g, '\\"')
.replace(/\n/g, '\\n')
.replace(/\r/g, '\\r') + '"';
.replace(/\r/g, '\\r')
.replace(/\u2028/g, '\\u2028') // Per Ecma-262 7.3 + 7.8.4
.replace(/\u2029/g, '\\u2029') + '"';
},

setupHelper: function(paramSize, name, missingParams) {
Expand Down
4 changes: 4 additions & 0 deletions spec/qunit_spec.js
Expand Up @@ -1408,6 +1408,10 @@ test('GH-458: Scoped this identifier', function() {
shouldCompileTo('{{./foo}}', {foo: 'bar'}, 'bar');
});

test('GH-375: Unicode line terminators', function() {
shouldCompileTo('\u2028', {}, '\u2028');
});

suite('Utils');

test('escapeExpression', function() {
Expand Down

0 comments on commit 4d66d0c

Please sign in to comment.