mirror of
https://github.com/discourse/discourse.git
synced 2025-06-04 11:11:13 +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:
@ -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
|
||||
|
Reference in New Issue
Block a user