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:
Martin Brennan
2025-03-17 15:56:19 +10:00
committed by GitHub
parent d0a5fd5e21
commit 327375abee
7 changed files with 223 additions and 90 deletions

View File

@ -40,6 +40,20 @@ class FileHelper
filename.match?(supported_playable_media_regexp)
end
# https://guides.rubyonrails.org/security.html#file-uploads
def self.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.*(\\|/)}, ""
# Replace all non alphanumeric, underscore
# or periods with underscore
name.gsub! /[^\w\.\-]/, "_"
# Finally, replace all double underscores with a single one
name.gsub! /_+/, "_"
end
end
class FakeIO
attr_accessor :status
end