{"record":{"id":"34276381550f8afe","repo":"larksuite/cli","slug":"invalid-profile-name-q-contains-invalid-characte","errorCode":null,"errorMessage":"invalid profile name %q: contains invalid character %q","messagePattern":"invalid profile name %q: contains invalid character %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/core/config.go","lineNumber":174,"sourceCode":"}\n\n// ValidateProfileName checks that a profile name is valid.\n// Rejects empty names, whitespace, control characters, and shell-problematic characters,\n// but allows Unicode letters (e.g. Chinese, Japanese) for localized profile names.\nfunc ValidateProfileName(name string) error {\n\tif name == \"\" {\n\t\treturn fmt.Errorf(\"profile name cannot be empty\")\n\t}\n\tif utf8.RuneCountInString(name) > 64 {\n\t\treturn fmt.Errorf(\"profile name %q is too long (max 64 characters)\", name)\n\t}\n\tfor _, r := range name {\n\t\tif r <= 0x1F || r == 0x7F { // control characters\n\t\t\treturn fmt.Errorf(\"invalid profile name %q: contains control characters\", name)\n\t\t}\n\t\tswitch r {\n\t\tcase ' ', '\\t', '/', '\\\\', '\"', '\\'', '`', '$', '#', '!', '&', '|', ';', '(', ')', '{', '}', '[', ']', '<', '>', '?', '*', '~':\n\t\t\treturn fmt.Errorf(\"invalid profile name %q: contains invalid character %q\", name, r)\n\t\t}\n\t}\n\treturn nil\n}\n\n// CliConfig is the resolved single-app config used by downstream code.\ntype CliConfig struct {\n\tProfileName         string\n\tAppID               string\n\tAppSecret           string\n\tBrand               LarkBrand\n\tDefaultAs           Identity // AsUser | AsBot | AsAuto | \"\" (from config file)\n\tUserOpenId          string\n\tUserName            string\n\tLang                i18n.Lang\n\tSupportedIdentities uint8 `json:\"-\"` // bitflag: 1=user, 2=bot; set by credential provider\n}\n","sourceCodeStart":156,"sourceCodeEnd":192,"githubUrl":"https://github.com/larksuite/cli/blob/7fd6ef3c07182257ce776cdc5a614e122d5bd4b3/internal/core/config.go#L156-L192","documentation":"Beyond control characters, ValidateProfileName rejects shell-problematic characters: whitespace, path separators, quotes, and metacharacters ($ ` # ! & | ; parentheses braces brackets < > ? * ~), keeping profile names safe in config keys and shell usage.","triggerScenarios":"A name containing any of ' ', \\t, /, \\\\, quotes, backtick, $, #, !, &, |, ;, (), {}, [], <, >, ?, *, ~ is passed to ValidateProfileName.","commonSituations":"Using an email address as a profile name; a name with a space like \"my work\"; shell expansions embedded by double-quoted interpolation.","solutions":["Remove the offending character — prefer letters, digits, '-', '_', '.'","Replace spaces with hyphens (\"my-work\")","Sanitize generated names with a replacement pass before validation"],"exampleFix":"// before\nname := \"my work/profile\"\n// after\nname := strings.NewReplacer(\" \", \"-\", \"/\", \"-\").Replace(\"my work/profile\") // \"my-work-profile\"","handlingStrategy":"validation","validationCode":"func safeProfileName(s string) bool {\n    for _, r := range s {\n        if strings.ContainsRune(\" \\t/\\\\\\\"'`$#!&|;(){}[]<>?*~\", r) { return false }\n    }\n    return s != \"\"\n}","typeGuard":null,"tryCatchPattern":"if err := core.ValidateProfileName(name); err != nil {\n    if strings.Contains(err.Error(), \"invalid character\") {\n        name = strings.Map(func(r rune) rune {\n            if strings.ContainsRune(\" \\t/\\\\\\\"'`$#!&|;(){}[]<>?*~\", r) { return '-' }\n            return r\n        }, name)\n        return core.ValidateProfileName(name)\n    }\n    return err\n}","preventionTips":["Use only [A-Za-z0-9._-] for profile names","Never use emails or paths as profile names","Run ValidateProfileName in CI for any script that generates profiles"],"tags":["go","validation","shell-safe-names"],"backgroundTag":"invalid-profile-name-characters","analyzedSha":"7fd6ef3c07182257ce776cdc5a614e122d5bd4b3","analyzedAt":"2026-09-04T21:17:44.649Z","contentChangedAt":"2026-09-04T21:17:44.649Z","schemaVersion":2},"datasetVersion":"2026-09-12T02:17:10.037Z"}