{"record":{"id":"65f69fcaa65bc313","repo":"hashicorp/terraform","slug":"os-portion-must-not-contain-whitespace","errorCode":null,"errorMessage":"OS portion must not contain whitespace","messagePattern":"OS portion must not contain whitespace","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/getproviders/types.go","lineNumber":123,"sourceCode":"\tswitch {\n\tcase p.OS != other.OS:\n\t\treturn p.OS < other.OS\n\tdefault:\n\t\treturn p.Arch < other.Arch\n\t}\n}\n\n// ParsePlatform parses a string representation of a platform, like\n// \"linux_amd64\", or returns an error if the string is not valid.\nfunc ParsePlatform(str string) (Platform, error) {\n\tparts := strings.Split(str, \"_\")\n\tif len(parts) != 2 {\n\t\treturn Platform{}, fmt.Errorf(\"must be two words separated by an underscore\")\n\t}\n\n\tos, arch := parts[0], parts[1]\n\tif strings.ContainsAny(os, \" \\t\\n\\r\") {\n\t\treturn Platform{}, fmt.Errorf(\"OS portion must not contain whitespace\")\n\t}\n\tif strings.ContainsAny(arch, \" \\t\\n\\r\") {\n\t\treturn Platform{}, fmt.Errorf(\"architecture portion must not contain whitespace\")\n\t}\n\n\treturn Platform{\n\t\tOS:   os,\n\t\tArch: arch,\n\t}, nil\n}\n\n// CurrentPlatform is the platform where the current program is running.\n//\n// If attempting to install providers for use on the same system where the\n// installation process is running, this is the right platform to use.\nvar CurrentPlatform = Platform{\n\tOS:   runtime.GOOS,\n\tArch: runtime.GOARCH,","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/hashicorp/terraform/blob/d32a084675427f5ac3f7d2868578ef8b2c1dc525/internal/getproviders/types.go#L105-L141","documentation":"Returned by ParsePlatform when the OS portion (the substring before the underscore) contains any of space, tab, newline, or carriage return. Emitted only after the two-part split succeeds; it guards against whitespace that the underscore split would not catch.","triggerScenarios":"A platform string like 'linu x_amd64', '\\tlinux_amd64', 'linux\\n_amd64' where the OS token has embedded whitespace. Usually a copy-paste or shell-quoting artifact.","commonSituations":"Trailing space introduced by shell expansion; tab from a malformed config file; copy-paste from a table introducing a non-breaking space (note: NBSP is U+00A0, technically not in the ContainsAny set, but a regular space often is).","solutions":["Trim surrounding whitespace from the platform string before parsing.","Quote CLI args and config values to prevent shell word-splitting.","Audit the source of the platform string for stray spaces or tabs.","If the value is user-supplied, validate with strings.TrimSpace before ParsePlatform."],"exampleFix":"// before\np, err := ParsePlatform(\" linux_amd64\")\n// after\np, err := ParsePlatform(strings.TrimSpace(\" linux_amd64\"))","handlingStrategy":"validation","validationCode":"// Reject OS tokens with whitespace before parsing.\nfunc validatePlatformTokens(s string) error {\n    parts := strings.Split(s, \"_\")\n    if len(parts) != 2 { return errors.New(\"bad shape\") }\n    if strings.ContainsAny(parts[0], \" \\t\\n\\r\") { return errors.New(\"OS has whitespace\") }\n    return nil\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Call strings.TrimSpace on platform strings sourced from files or flags.","Quote shell variables that may contain spaces.","Lint config files for stray whitespace."],"tags":["platform","validation","whitespace","parsing","getproviders"],"backgroundTag":null,"analyzedSha":"d32a084675427f5ac3f7d2868578ef8b2c1dc525","analyzedAt":"2026-08-11T18:43:52.779Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}