Handle case where space name is made entirely of whitespace (#23691) (#23783)

* handle case where space name is made entirely of whitespace

* update space name validation
This commit is contained in:
Larry Gregory 2018-10-03 14:24:01 -04:00 committed by GitHub
parent b893aa76f4
commit e45921e449
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 33 additions and 2 deletions

View file

@ -1,5 +1,17 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`renders with a space name entirely made of whitespace 1`] = `
<EuiAvatar
color="#DB1374"
data-test-subj="space-avatar-"
initials=""
initialsLength={2}
name=""
size="m"
type="space"
/>
`;
exports[`renders without crashing 1`] = `
<EuiAvatar
color="#BFA180"

View file

@ -12,3 +12,8 @@ test('renders without crashing', () => {
const wrapper = shallow(<SpaceAvatar space={{ name: '', id: '' }} />);
expect(wrapper).toMatchSnapshot();
});
test('renders with a space name entirely made of whitespace', () => {
const wrapper = shallow(<SpaceAvatar space={{ name: ' ', id: '' }} />);
expect(wrapper).toMatchSnapshot();
});

View file

@ -18,11 +18,13 @@ interface Props {
export const SpaceAvatar = (props: Props) => {
const { space, size, ...rest } = props;
const spaceName = space.name ? space.name.trim() : '';
return (
<EuiAvatar
type="space"
data-test-subj={`space-avatar-${space.id}`}
name={space.name || ''}
name={spaceName}
size={size || 'm'}
initialsLength={MAX_SPACE_INITIALS}
initials={getSpaceInitials(space)}

View file

@ -34,6 +34,18 @@ describe('validateSpaceName', () => {
});
});
test('it cannot be composed entirely of whitespace', () => {
const space = {
id: '',
name: ' ',
};
expect(validator.validateSpaceName(space)).toEqual({
isInvalid: true,
error: `Name is required`,
});
});
test('it cannot exceed 1024 characters', () => {
const space = {
id: '',

View file

@ -31,7 +31,7 @@ export class SpaceValidator {
return valid();
}
if (!space.name) {
if (!space.name || !space.name.trim()) {
return invalid(`Name is required`);
}