FIX: Prevent double slashes in Ember templates paths (#12630)

diff --git a/app/models/theme.rb b/app/models/theme.rb
index 4803f1d..ef93577 100644
--- a/app/models/theme.rb
+++ b/app/models/theme.rb
@@ -128,7 +128,7 @@ class Theme < ActiveRecord::Base
     SvgSprite.expire_cache
   end
 
-  BASE_COMPILER_VERSION = 45
+  BASE_COMPILER_VERSION = 46
   def self.compiler_version
     get_set_cache "compiler_version" do
       dependencies = [
diff --git a/lib/theme_javascript_compiler.rb b/lib/theme_javascript_compiler.rb
index 4917865..6fb33e7 100644
--- a/lib/theme_javascript_compiler.rb
+++ b/lib/theme_javascript_compiler.rb
@@ -183,7 +183,11 @@ class ThemeJavascriptCompiler
 
   # TODO Error handling for handlebars templates
   def append_ember_template(name, hbs_template)
-    name = "javascripts/#{name}" if !name.start_with?("javascripts/")
+    if !name.start_with?("javascripts/")
+      prefix = "javascripts"
+      prefix += "/" if !name.start_with?("/")
+      name = prefix + name
+    end
     name = name.inspect
     compiled = EmberTemplatePrecompiler.new(@theme_id).compile(hbs_template)
     # the `'Ember' in window` check is needed for no_ember pages
diff --git a/spec/lib/theme_javascript_compiler_spec.rb b/spec/lib/theme_javascript_compiler_spec.rb
index e82bb64..e15adc5 100644
--- a/spec/lib/theme_javascript_compiler_spec.rb
+++ b/spec/lib/theme_javascript_compiler_spec.rb
@@ -127,4 +127,18 @@ describe ThemeJavascriptCompiler do
       expect(compiler.content.to_s).to include("addRawTemplate(\"#{name}.hbs\"")
     end
   end
+
+  describe "#append_ember_template" do
+    let(:compiler) { ThemeJavascriptCompiler.new(1, 'marks') }
+    it 'prepends `javascripts/` to template name if it is not prepended' do
+      compiler.append_ember_template("/connectors/blah-1", "{{var}}")
+      expect(compiler.content.to_s).to include('Ember.TEMPLATES["javascripts/connectors/blah-1"]')
+
+      compiler.append_ember_template("connectors/blah-2", "{{var}}")
+      expect(compiler.content.to_s).to include('Ember.TEMPLATES["javascripts/connectors/blah-2"]')
+
+      compiler.append_ember_template("javascripts/connectors/blah-3", "{{var}}")
+      expect(compiler.content.to_s).to include('Ember.TEMPLATES["javascripts/connectors/blah-3"]')
+    end
+  end
 end

GitHub sha: 10563443

1 Like

This commit appears in #12630 which was approved by CvX. It was merged by OsamaSayegh.