diff --git a/app/services/ember-cli.js b/app/services/ember-cli.js index 79363b97..29bf60b1 100644 --- a/app/services/ember-cli.js +++ b/app/services/ember-cli.js @@ -270,7 +270,8 @@ export default Ember.Service.extend({ // let templateCode = Ember.HTMLBars.precompile(code || ''); // Compiles all templates at runtime. - return this.compileJs('export default Ember.HTMLBars.compile(`' + (code || '') + '`);', filePath); + const mungedCode = (code || '').replace(/\\/g, "\\\\"); // Prevent backslashes from being escaped + return this.compileJs('export default Ember.HTMLBars.compile(`' + mungedCode + '`);', filePath); }, compileCss(code, moduleName) { diff --git a/tests/acceptance/escape-test.js b/tests/acceptance/escape-test.js new file mode 100644 index 00000000..2430fdde --- /dev/null +++ b/tests/acceptance/escape-test.js @@ -0,0 +1,31 @@ +import Ember from 'ember'; +import { module, test } from 'qunit'; +import startApp from 'ember-twiddle/tests/helpers/start-app'; + +module('Acceptance | escaping moustaches', { + beforeEach: function() { + this.application = startApp(); + }, + + afterEach: function() { + Ember.run(this.application, 'destroy'); + } +}); + +test('Able to escape moustache tag', function(assert) { + + const files = [ + { + filename: "application.template.hbs", + content: "\\{{Moustache}}" + } + ]; + + runGist(files); + + andThen(function() { + const outputDiv = 'div'; + + assert.equal(outputContents(outputDiv), '{{Moustache}}', 'Moustache tag is escaped'); + }); +});