github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/util/fileutil/escape.go (about)

     1  // Copyright 2017 The Cockroach Authors.
     2  //
     3  // Use of this software is governed by the Business Source License
     4  // included in the file licenses/BSL.txt.
     5  //
     6  // As of the Change Date specified in that file, in accordance with
     7  // the Business Source License, use of this software will be governed
     8  // by the Apache License, Version 2.0, included in the file
     9  // licenses/APL.txt.
    10  
    11  package fileutil
    12  
    13  import "regexp"
    14  
    15  // EscapeFilename replaces bad characters in a filename with safe equivalents.
    16  // The only character disallowed on Unix systems is the path separator "/".
    17  // Windows is more restrictive; banned characters on Windows are listed here:
    18  // https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx
    19  func EscapeFilename(s string) string {
    20  	return regexp.MustCompile(`[<>:"\/|?*\x00-\x1f]`).ReplaceAllString(s, "_")
    21  }