Skip to content

A platform for community discussion. Free, open, simple.

FIX: Correctly import theme assets with spaces in filename

David Taylorb1b8c37e62b6
diff --git a/app/models/remote_theme.rb b/app/models/remote_theme.rb
index 53a4cd21a3b..70ac5160937 100644
--- a/app/models/remote_theme.rb
+++ b/app/models/remote_theme.rb
@@ -107,7 +107,9 @@ class RemoteTheme < ActiveRecord::Base
theme_info["assets"]&.each do |name, relative_path|
if path = importer.real_path(relative_path)
- upload = UploadCreator.new(File.open(path), File.basename(relative_path), for_theme: true).create_for(theme.user_id)
+ new_path = "#{File.dirname(path)}/#{SecureRandom.hex}#{File.extname(path)}"
+ File.rename(path, new_path) # OptimizedImage has strict file name restrictions, so rename temporarily
+ upload = UploadCreator.new(File.open(new_path), File.basename(relative_path), for_theme: true).create_for(theme.user_id)
theme.set_field(target: :common, name: name, type: :theme_upload_var, upload_id: upload.id)
end
end