mirror of https://github.com/docker/cli.git
opts/envfile: trim all leading whitespace in a line
Signed-off-by: Matt Robenolt <matt@ydekproductions.com>
This commit is contained in:
parent
091f800069
commit
869e08a12b
|
@ -26,13 +26,12 @@ func ParseEnvFile(filename string) ([]string, error) {
|
|||
lines := []string{}
|
||||
scanner := bufio.NewScanner(fh)
|
||||
for scanner.Scan() {
|
||||
line := scanner.Text()
|
||||
// trim the line from all leading whitespace first
|
||||
line := strings.TrimLeft(scanner.Text(), whiteSpaces)
|
||||
// line is not empty, and not starting with '#'
|
||||
if len(line) > 0 && !strings.HasPrefix(line, "#") {
|
||||
data := strings.SplitN(line, "=", 2)
|
||||
|
||||
// trim the front of a variable, but nothing else
|
||||
variable := strings.TrimLeft(data[0], whiteSpaces)
|
||||
variable := data[0]
|
||||
|
||||
if !EnvironmentVariableRegexp.MatchString(variable) {
|
||||
return []string{}, ErrBadEnvVariable{fmt.Sprintf("variable '%s' is not a valid environment variable", variable)}
|
||||
|
|
|
@ -29,7 +29,12 @@ func TestParseEnvFileGoodFile(t *testing.T) {
|
|||
|
||||
_foobar=foobaz
|
||||
`
|
||||
|
||||
// Adding a newline + a line with pure whitespace.
|
||||
// This is being done like this instead of the block above
|
||||
// because it's common for editors to trim trailing whitespace
|
||||
// from lines, which becomes annoying since that's the
|
||||
// exact thing we need to test.
|
||||
content += "\n \t "
|
||||
tmpFile := tmpFileWithContent(content, t)
|
||||
defer os.Remove(tmpFile)
|
||||
|
||||
|
|
Loading…
Reference in New Issue