class ActiveStorage::Filename
def sanitized
ActiveStorage::Filename.new("foo/bar.jpg").sanitized # => "foo-bar.jpg"
ActiveStorage::Filename.new("foo:bar.jpg").sanitized # => "foo-bar.jpg"
Returns the sanitized filename.
def sanitized @filename.encode(Encoding::UTF_8, invalid: :replace, undef: :replace, replace: "�").strip.tr("\u{202E}%$|:;/\t\r\n\\", "-") end