Skip to content

Commit

Permalink
client/manager_sql: return an empty slice if string is empty (#491)
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamedh Fazal <mohamedhfazal@gmail.com>
  • Loading branch information
mfzl authored and arekkas committed Jun 5, 2017
1 parent 9e0cb23 commit e88fdb7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
8 changes: 4 additions & 4 deletions client/manager_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ func (d *sqlData) ToClient() *Client {
ID: d.ID,
Name: d.Name,
Secret: d.Secret,
RedirectURIs: strings.Split(d.RedirectURIs, "|"),
GrantTypes: strings.Split(d.GrantTypes, "|"),
ResponseTypes: strings.Split(d.ResponseTypes, "|"),
RedirectURIs: pkg.SplitNonEmpty(d.RedirectURIs, "|"),
GrantTypes: pkg.SplitNonEmpty(d.GrantTypes, "|"),
ResponseTypes: pkg.SplitNonEmpty(d.ResponseTypes, "|"),
Scope: d.Scope,
Owner: d.Owner,
PolicyURI: d.PolicyURI,
TermsOfServiceURI: d.TermsOfServiceURI,
ClientURI: d.ClientURI,
LogoURI: d.LogoURI,
Contacts: strings.Split(d.Contacts, "|"),
Contacts: pkg.SplitNonEmpty(d.Contacts, "|"),
Public: d.Public,
}
}
Expand Down
1 change: 1 addition & 0 deletions client/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ func TestCreateGetDeleteClient(t *testing.T) {
assert.Equal(t, "bar", nc.TermsOfServiceURI, "%s", k)
assert.Equal(t, "name-new", nc.Name, "%s", k)
assert.EqualValues(t, []string{"http://redirect/new"}, nc.GetRedirectURIs(), "%s", k)
assert.Zero(t, len(nc.Contacts))

err = m.DeleteClient("1234")
assert.Nil(t, err)
Expand Down
13 changes: 13 additions & 0 deletions pkg/split_string.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package pkg

import "strings"

// SplitNonEmpty is a special case of strings.Split
// which returns an empty slice if string is empty
func SplitNonEmpty(s, sep string) []string {
if s == "" {
return nil
}

return strings.Split(s, sep)
}

0 comments on commit e88fdb7

Please sign in to comment.