Skip to content

Commit

Permalink
fix(html2js): handling of the backslash character
Browse files Browse the repository at this point in the history
At the html2js preprocessor escape the backslash character when this is
present in a template

Closes karma-runner#583
  • Loading branch information
lgalfaso committed Jun 30, 2013
1 parent 8606695 commit 0f0a089
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/preprocessors/Html2js.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var template = 'angular.module(\'%s\', []).run(function($templateCache) {\n' +
'});\n';

var escapeContent = function(content) {
return content.replace(/'/g, '\\\'').replace(/\r?\n/g, '\\n\' +\n \'');
return content.replace(/\\/g, '\\\\').replace(/'/g, '\\\'').replace(/\r?\n/g, '\\n\' +\n \'');
};

var Html2js = function(content, file, basePath, done) {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/preprocessors/Html2js.spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,11 @@ describe 'preprocessors html2js', ->
process 'first\r\nsecond', file, '/base', (processedContent) ->
expect(processedContent).to.not.contain '\r'
done()


it 'should preserve the backslash character', (done) ->
file = new File '/base/path/file.html'

process 'first\\second', file, '/base', (processedContent) ->
expect(processedContent).to.contain "'first\\\\second'"
done()

0 comments on commit 0f0a089

Please sign in to comment.