Skip to content

Commit

Permalink
Merge pull request #5 from whilp/handle-spaces
Browse files Browse the repository at this point in the history
Allow spaces in envvar values
  • Loading branch information
whilp committed Oct 14, 2014
2 parents 383ca45 + d6eba61 commit b259cde
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
10 changes: 9 additions & 1 deletion envcrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,17 @@ func decrypt(path string) ([]byte, error) {
return out, nil
}

func isNewLine(r rune) bool {
switch r {
case '\n':
return true
}
return false
}

// The parse function splits a byte array on whitespace.
func parse(data []byte) ([]string, error) {
return strings.Fields(string(data)), nil
return strings.FieldsFunc(string(data), isNewLine), nil
}

// The run function runs a command in an environment.
Expand Down
8 changes: 8 additions & 0 deletions envcrypt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ func TestParseOK(t *testing.T) {
t.Errorf("")
}
}

func TestParseSpaces(t *testing.T) {
in := []byte("FOO=bar baz\n")
out := []string{"FOO=bar baz"}
if result, _ := parse(in); result[0] != out[0] {
t.Errorf("")
}
}

0 comments on commit b259cde

Please sign in to comment.