Skip to content

Commit

Permalink
Merge pull request #147 from underscorebrody/linebreak_fix
Browse files Browse the repository at this point in the history
Fixes issue with carriage return escaping
  • Loading branch information
underscorebrody committed Jan 19, 2016
2 parents 8e50ad4 + 5bc4418 commit 530d79a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
5 changes: 5 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ module.exports = function(grunt) {
options: {
quotes: 'single'
}
},

linebreak: {
src: 'test/fixtures/linebreak.html',
dest: 'tmp/linebreak.js',
}
}
});
Expand Down
1 change: 1 addition & 0 deletions tasks/lib/compiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ var Compiler = function(grunt, options, cwd, expanded) {
var quote = options.quotes === 'single' ? '\'' : '"';

line = line.replace(/\n/g, '\\n');
line = line.replace(/\r/g, '\\r');
var quoteRegExp = new RegExp(quote, 'g');
line = line.replace(quoteRegExp, '\\' + quote);

Expand Down
12 changes: 11 additions & 1 deletion test/angular-templates_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,16 @@ exports.ngtemplates = {

test.equal(expected, actual);
test.done();
}
},

linebreak: function(test) {
test.expect(1);

var actual = grunt.file.read('tmp/linebreak.js');
var expected = grunt.file.read('test/expected/linebreak.js');

test.equal(expected, actual);
test.done();
}

};
10 changes: 10 additions & 0 deletions test/expected/linebreak.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
angular.module('linebreak').run(['$templateCache', function($templateCache) {
'use strict';

$templateCache.put('test/fixtures/linebreak.html',
"<textarea placeholder=\"This is a carriage return.\r" +
"\n" +
"Also also a newline.\"></textarea>"
);

}]);
2 changes: 2 additions & 0 deletions test/fixtures/linebreak.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<textarea placeholder="This is a carriage return.
Also also a newline."></textarea>

0 comments on commit 530d79a

Please sign in to comment.