[MM-54288] Support Packet V2 (#29403)
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
091d1bba8b
Коммит
8d4bf4bae0
@@ -6,6 +6,8 @@ package utils
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func CommonBaseSearchPaths() []string {
|
||||
@@ -111,3 +113,25 @@ func FindDirRelBinary(dir string) (string, bool) {
|
||||
}
|
||||
return found, true
|
||||
}
|
||||
|
||||
// Valid characters are: alphanumeric, dash, underscore
|
||||
var safeFileNameRegex = regexp.MustCompile(`[^\w\-\_]`)
|
||||
|
||||
// SanitizeFileName takes a string and returns a safe file name without an extension.
|
||||
func SanitizeFileName(input string) string {
|
||||
// Trim leading or trailing dots or spaces
|
||||
safeName := strings.Trim(input, ". ")
|
||||
// Replace dots with nothing
|
||||
safeName = strings.ReplaceAll(safeName, ".", "")
|
||||
|
||||
// Replace all invalid characters with an underscore
|
||||
safeName = safeFileNameRegex.ReplaceAllString(safeName, "_")
|
||||
|
||||
// Limit length
|
||||
const maxLength = 100
|
||||
if len(safeName) > maxLength {
|
||||
safeName = safeName[:maxLength]
|
||||
}
|
||||
|
||||
return safeName
|
||||
}
|
||||
|
||||
Ссылка в новой задаче
Block a user