Skip to content

Commit a776386

Browse files
committed
Fix problem with multi-line comments breaking compileAngularTemplates step due to invalid JS generated for the template
The issue was introduced in a47ecc2. When a ng.html file contains multi-line comments Meteor failed on the console with error like "Unexpected token ILLEGAL" due to the generated JS that adds the html to the template cache was broken. For example this could break your app: ``` <div> <!-- <div> Containing comments on multiple lines breaks the build </div> --> </div> ``` In order to properly fix that - the best future proof approach is to JSON.stringify the strings as this ensures any JS special character is properly escaped and turned into string literal.
1 parent 2792b98 commit a776386

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

.docs/angular-meteor/client/views/someshit.ng.html

Whitespace-only changes.

plugin/handler.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Plugin.registerSourceHandler('ng.html', {
1515
// Ticket here: https://github.com/Urigo/angular-meteor/issues/169
1616
// A standardized solution to this problem might be on its way, see this ticket:
1717
// https://github.com/meteor/windows-preview/issues/47
18-
'$templateCache.put(\'' + compileStep.inputPath.replace(/\\/g, "/") + '\', \'' +
19-
minify(contents.replace(/'/g, "\\'"), {
18+
'$templateCache.put(' + JSON.stringify(compileStep.inputPath.replace(/\\/g, "/")) + ', ' +
19+
JSON.stringify(minify(contents, {
2020
collapseWhitespace : true,
2121
conservativeCollapse : true,
2222
minifyJS : true,
2323
minifyCSS : true,
2424
processScripts : ['text/ng-template']
25-
}) + '\');' +
25+
})) + ');' +
2626
'}]);';
2727

2828
compileStep.addJavaScript({

0 commit comments

Comments
 (0)