mirror of
https://github.com/discourse/discourse.git
synced 2025-05-24 14:12:10 +08:00
FIX: Use theme screenshot names in theme fields (#31852)
Currently we allow for 2 theme screenshots to be specified, with a lightweight spec to allow both a light and dark version of the screenshot. However, we were not storing this screenshot name anywhere, so we would not be able to use it for light/dark switching. This commit fixes that issue, and also does some general refactoring around theme screenshots, and adds more tests.
This commit is contained in:
@ -38,18 +38,6 @@ module Compression
|
||||
Pathname.new(filename).realpath.to_s
|
||||
end
|
||||
|
||||
# https://guides.rubyonrails.org/security.html#file-uploads
|
||||
def sanitize_filename(filename)
|
||||
filename.strip.tap do |name|
|
||||
# NOTE: File.basename doesn't work right with Windows paths on Unix
|
||||
# get only the filename, not the whole path
|
||||
name.sub! %r{\A.*(\\|/)}, ""
|
||||
# Finally, replace all non alphanumeric, underscore
|
||||
# or periods with underscore
|
||||
name.gsub! /[^\w\.\-]/, "_"
|
||||
end
|
||||
end
|
||||
|
||||
def calculate_available_size(max_size)
|
||||
1024**2 * (max_size / 1.049) # Mb to Mib
|
||||
end
|
||||
|
@ -9,7 +9,7 @@ module Compression
|
||||
end
|
||||
|
||||
def compress(path, target_name)
|
||||
tar_filename = sanitize_filename("#{target_name}.tar")
|
||||
tar_filename = FileHelper.sanitize_filename("#{target_name}.tar")
|
||||
Discourse::Utils.execute_command(
|
||||
"tar",
|
||||
"--create",
|
||||
|
Reference in New Issue
Block a user