add a check to prevent panics (#5471)

This commit is contained in:
Becca Petrin 2018-10-05 09:23:06 -07:00 committed by Jeff Mitchell
parent 380796f4fe
commit 3e3c195773
2 changed files with 5 additions and 0 deletions

View file

@ -377,6 +377,10 @@ func (c *Client) GetLdapGroups(cfg *ConfigEntry, conn Connection, userDN string,
// EscapeLDAPValue is exported because a plugin uses it outside this package. // EscapeLDAPValue is exported because a plugin uses it outside this package.
func EscapeLDAPValue(input string) string { func EscapeLDAPValue(input string) string {
if input == "" {
return ""
}
// RFC4514 forbids un-escaped: // RFC4514 forbids un-escaped:
// - leading space or hash // - leading space or hash
// - trailing space // - trailing space

View file

@ -11,6 +11,7 @@ func TestLDAPEscape(t *testing.T) {
"test,hel+lo": "test\\,hel\\+lo", "test,hel+lo": "test\\,hel\\+lo",
"test\\hello": "test\\\\hello", "test\\hello": "test\\\\hello",
" test ": "\\ test \\ ", " test ": "\\ test \\ ",
"": "",
} }
for test, answer := range testcases { for test, answer := range testcases {