lib/ddr/utils.rb in ddr-models-1.12.3 vs lib/ddr/utils.rb in ddr-models-1.13.0
- old
+ new
@@ -51,9 +51,16 @@
def self.file_uri?(uri)
return false unless uri
URI.parse(uri).scheme == "file"
end
+ def self.sanitize_filename file_name
+ return unless file_name
+ raise ArgumentError, "file_name argument must be a string" unless file_name.is_a?(String)
+ raise ArgumentError, "file_name argument must not include path" if file_name.include?(File::SEPARATOR)
+ file_name.gsub(/[^\w\.\-]/,"_")
+ end
+
# Return file path for URI string
# Should reverse .path_to_uri
# "file:/path/to/file" => "/path/to/file"
def self.path_from_uri(uri)
URI.unescape(URI.parse(uri).path)
\ No newline at end of file