From f92dcb796855e7b489f5d13cf449d95899bc8d44 Mon Sep 17 00:00:00 2001 From: kayrus Date: Fri, 28 Aug 2015 12:38:47 +0200 Subject: [PATCH] cloudinit: trim trailing whitespaces in #cloud-config header --- config/config.go | 7 +++---- initialize/user_data_test.go | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/config/config.go b/config/config.go index 441e1ed..94dfe51 100644 --- a/config/config.go +++ b/config/config.go @@ -19,6 +19,7 @@ import ( "reflect" "regexp" "strings" + "unicode" "github.com/coreos/coreos-cloudinit/Godeps/_workspace/src/github.com/coreos/yaml" ) @@ -49,10 +50,8 @@ type CoreOS struct { func IsCloudConfig(userdata string) bool { header := strings.SplitN(userdata, "\n", 2)[0] - // Explicitly trim the header so we can handle user-data from - // non-unix operating systems. The rest of the file is parsed - // by yaml, which correctly handles CRLF. - header = strings.TrimSuffix(header, "\r") + // Trim trailing whitespaces + header = strings.TrimRightFunc(header, unicode.IsSpace) return (header == "#cloud-config") } diff --git a/initialize/user_data_test.go b/initialize/user_data_test.go index 1d88369..7a5acc9 100644 --- a/initialize/user_data_test.go +++ b/initialize/user_data_test.go @@ -47,7 +47,7 @@ func TestParseHeaderCRLF(t *testing.T) { } func TestParseConfigCRLF(t *testing.T) { - contents := "#cloud-config\r\nhostname: foo\r\nssh_authorized_keys:\r\n - foobar\r\n" + contents := "#cloud-config \r\nhostname: foo\r\nssh_authorized_keys:\r\n - foobar\r\n" ud, err := ParseUserData(contents) if err != nil { t.Fatalf("Failed parsing config: %v", err)