{"record":{"id":"b24b3911a8ae016a","repo":"golang/go","slug":"invalid-newline-in-s-value","errorCode":null,"errorMessage":"invalid newline in %s=... value","messagePattern":"invalid newline in (.+?)=\\.\\.\\. value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/envcmd/env.go","lineNumber":700,"sourceCode":"\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"invalid %s: %v\", key, err)\n\t\t}\n\t\tif len(args) == 0 {\n\t\t\treturn fmt.Errorf(\"%s entry cannot contain only space\", key)\n\t\t}\n\t\tif !filepath.IsAbs(args[0]) && args[0] != filepath.Base(args[0]) {\n\t\t\treturn fmt.Errorf(\"%s entry is relative; must be absolute path: %q\", key, args[0])\n\t\t}\n\t}\n\n\tif !utf8.ValidString(val) {\n\t\treturn fmt.Errorf(\"invalid UTF-8 in %s=... value\", key)\n\t}\n\tif strings.Contains(val, \"\\x00\") {\n\t\treturn fmt.Errorf(\"invalid NUL in %s=... value\", key)\n\t}\n\tif strings.ContainsAny(val, \"\\v\\r\\n\") {\n\t\treturn fmt.Errorf(\"invalid newline in %s=... value\", key)\n\t}\n\treturn nil\n}\n\nfunc readEnvFileLines(mustExist bool) []string {\n\tfile, _, err := cfg.EnvFile()\n\tif file == \"\" {\n\t\tif mustExist {\n\t\t\tbase.Fatalf(\"go: cannot find go env config: %v\", err)\n\t\t}\n\t\treturn nil\n\t}\n\tdata, err := os.ReadFile(file)\n\tif err != nil && (!os.IsNotExist(err) || mustExist) {\n\t\tbase.Fatalf(\"go: reading go env config: %v\", err)\n\t}\n\tlines := strings.SplitAfter(string(data), \"\\n\")\n\tif lines[len(lines)-1] == \"\" {","sourceCodeStart":682,"sourceCodeEnd":718,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/envcmd/env.go#L682-L718","documentation":"Returned by checkEnvWrite when the value written via `go env -w` contains any vertical tab, carriage return, or newline (\\v \\r \\n). The go env config file is one line per entry, so embedded newlines would corrupt the file structure.","triggerScenarios":"Any `go env -w KEY=...` value containing \\v, \\r, or \\n — typically multiline text pasted from a terminal, or values captured from `$(cmd)` whose output ends in a newline.","commonSituations":"Pasting multiline strings; command substitution that includes trailing newlines; copy-paste from documentation with line breaks; values containing Windows CRLF line endings.","solutions":["Trim trailing newlines from command substitution: assign then strip, or use `${var%$'\\n'}`.","Reject multiline values at your config layer with strings.ContainsAny(v, \"\\v\\r\\n\").","Use single-line equivalents (e.g. semicolons instead of newlines in compiler flags)."],"exampleFix":"# before\n$ go env -w GOPROXY=$(printf 'a\\nb')\nerror: invalid newline in GOPROXY=... value\n# after — strip newlines first\n$ go env -w GOPROXY=$(printf 'a\\nb' | tr -d '\\r\\n')","handlingStrategy":"validation","validationCode":"import \"strings\"\n\nif strings.ContainsAny(val, \"\\v\\r\\n\") {\n    return fmt.Errorf(\"value for %s contains newlines\", key)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Trim trailing newlines from command substitution before persisting.","Reject multiline values at config-ingestion time.","Prefer single-line representations in env-driven configs."],"tags":["config","env","validation","sanitization"],"backgroundTag":null,"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}