Skip to content
This repository has been archived by the owner on Jan 10, 2023. It is now read-only.

Commit

Permalink
This handles trailing whitespace in the IPv4 / IPv6 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
sargun committed Feb 6, 2019
1 parent 62f465a commit 29a0c19
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion vpc/ec2wrapper/ec2metadata.go
Expand Up @@ -202,10 +202,10 @@ func (mdc *EC2MetadataClientWrapper) getMetadata(path string) (string, error) {
}

func ipStringToList(ips string) []string {
ips = strings.TrimSpace(ips)
if ips == "" {
return []string{}
}
// This expects a non-\n terminated list of IPs separated by \n, and returns a normalized form
addresses := strings.Split(ips, "\n")
result := make([]string, len(addresses))
for idx, addr := range addresses {
Expand Down
2 changes: 1 addition & 1 deletion vpc/ec2wrapper/ec2metadata_test.go
Expand Up @@ -143,5 +143,5 @@ func TestMetadataService(t *testing.T) {

func TestIPStringToList(t *testing.T) {
assert.Equal(t, []string{}, ipStringToList(""))
assert.Equal(t, []string{"1.2.3.4", "4.5.6.8"}, ipStringToList("1.2.3.4\n4.5.6.8"))
assert.Equal(t, []string{"1.2.3.4", "4.5.6.8"}, ipStringToList("1.2.3.4\n4.5.6.8\n"))
}

0 comments on commit 29a0c19

Please sign in to comment.