Sha256: b697d5ba010512a1ccb7e15f935ba4af19bae1fdaf30939e08b861db1aecfa8c
Contents?: true
Size: 1004 Bytes
Versions: 26
Compression:
Stored size: 1004 Bytes
Contents
# Cleans up a filename to ensure it will work on filesystem. def File.sanitize(filename) filename = File.basename(filename.gsub("\\", "/")) # work-around for IE filename.gsub!(/[^a-zA-Z0-9\.\-\+_]/,"_") filename = "_#{filename}" if filename =~ /^\.+$/ filename end # _____ _ # |_ _|__ ___| |_ # | |/ _ \/ __| __| # | | __/\__ \ |_ # |_|\___||___/\__| # =begin test require 'test/unit' class TCFile < Test::Unit::TestCase def test_01_001 assert_equal( "This_is_a_test", File.sanitize('This is a test') ) end def test_01_001 assert_equal( "test", File.sanitize('This\is\test') ) end def test_01_001 assert_equal( "test", File.sanitize('This/is/test') ) end def test_01_001 assert_equal( "te_____st", File.sanitize('This/te#$#@!st') ) end def test_01_001 assert_equal( "_.", File.sanitize('.') ) end def test_01_001 assert_equal( "_....", File.sanitize('....') ) end end =end
Version data entries
26 entries across 26 versions & 1 rubygems