Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EuiAvatar does not handle a name composed entirely of whitespace #1230

Closed
legrego opened this issue Oct 3, 2018 · 0 comments
Closed

EuiAvatar does not handle a name composed entirely of whitespace #1230

legrego opened this issue Oct 3, 2018 · 0 comments
Labels

Comments

@legrego
Copy link
Member

legrego commented Oct 3, 2018

I noticed this while testing Kibana Spaces. The following crashes the component:

<EuiAvatar name={' '} />

The issue is caused by the code used to derive the avatar initials:

// A. Set to initials prop if exists (but trancate to 2 characters max unless length is supplied)
if (initials) {
  calculatedInitials = initials.substring(0, calculatedInitialsLength);
} else {
  if (name.split(' ').length > 1) {
    // B. If there are any spaces in the name, set to first letter of each word
    calculatedInitials = name.match(/\b(\w)/g).join('').substring(0, calculatedInitialsLength);
  } else {
    // C. Set to the name's initials truncated based on calculated length
    calculatedInitials = name.substring(0, calculatedInitialsLength);
  }
}

This condition fails in step "B" above, because the regular expression /\b(\w)/g returns null for a string composed entirely of whitespace.

For this scenario, I'd expect the initials to be calculated as an empty string. Granted, this ins't a common scenario, and likely not one we want to encourage in a UI, but we should at least make sure the component doesn't crash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant