ParseUserData: return nil on empty input string

This commit is contained in:
Jonathan Boulle
2014-06-27 23:58:27 -07:00
parent 231c0fa20b
commit d4e048a1f4
3 changed files with 15 additions and 3 deletions

View File

@@ -9,6 +9,9 @@ import (
)
func ParseUserData(contents string) (interface{}, error) {
if len(contents) == 0 {
return nil, nil
}
header := strings.SplitN(contents, "\n", 2)[0]
// Explicitly trim the header so we can handle user-data from

View File

@@ -47,3 +47,12 @@ func TestParseConfigCRLF(t *testing.T) {
t.Error("Parsed incorrect number of SSH keys")
}
}
func TestParseConfigEmpty(t *testing.T) {
i, e := ParseUserData(``)
if i != nil {
t.Error("ParseUserData of empty string returned non-nil unexpectedly")
} else if e != nil {
t.Error("ParseUserData of empty string returned error unexpectedly")
}
}