
# 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
