Skip to content

Commit

Permalink
Error instead of panicking if self link isn't long enough (#4887)
Browse files Browse the repository at this point in the history
Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored and rileykarson committed Nov 15, 2019
1 parent ad1d325 commit b486de7
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions google/self_link_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,14 @@ func GetLocationalResourcePropertiesFromSelfLinkString(selfLink string) (string,
}

s := strings.Split(parsed.Path, "/")

// This is a pretty bad way to tell if this is a self link, but stops us
// from accessing an index out of bounds and causing a panic. generally, we
// expect bad values to be partial URIs and names, so this will catch them
if len(s) < 9 {
return "", "", "", fmt.Errorf("value %s was not a self link", selfLink)
}

return s[4], s[6], s[8], nil
}

Expand Down

0 comments on commit b486de7

Please sign in to comment.