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

Follow-up to https://github.com/discourse/discourse/pull/12517
This commit is contained in:
Osama Sayegh 2021-04-07 14:08:29 +03:00 committed by GitHub
parent 93f74add7d
commit 105634435f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 20 additions and 2 deletions

View File

@ -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 = [

View File

@ -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

View File

@ -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