Skip to content

Commit 0cbdaae

Browse files
authored
fix(avatar): src with null value throws error (#15131)
1 parent 030ad76 commit 0cbdaae

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

projects/igniteui-angular/src/lib/avatar/avatar.component.spec.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,28 @@ describe('Avatar', () => {
170170

171171
expect(instance.src).toEqual("/assets/Test%20-%2017.jpg");
172172
});
173+
174+
it('should not throw error if src is null', () => {
175+
const fixture = TestBed.createComponent(InitImageAvatarComponent);
176+
fixture.detectChanges();
177+
expect(() => {
178+
const instance = fixture.componentInstance.avatar;
179+
instance.src = null;
180+
fixture.detectChanges();
181+
}).not.toThrow();
182+
});
183+
184+
it('avatar with [src] and fallback [initials] should not throw error if src is null', () => {
185+
const fixture = TestBed.createComponent(AvatarWithAttribsComponent);
186+
fixture.detectChanges();
187+
const instance = fixture.componentInstance.avatar;
188+
expect(instance.type).toEqual(IgxAvatarType.INITIALS);
189+
expect(instance.initials).toEqual('ZK');
190+
expect(() => {
191+
instance.src = null;
192+
fixture.detectChanges();
193+
}).not.toThrow();
194+
});
173195
});
174196

175197
@Component({

projects/igniteui-angular/src/lib/core/utils.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,6 @@ export function getComponentCssSizeVar(size: string) {
655655
* @param path - The URI path to be normalized.
656656
* @returns string encoded using the encodeURI function.
657657
*/
658-
export function normalizeURI(path: string) {
659-
return path.split('/').map(encodeURI).join('/');
660-
}
658+
export function normalizeURI(path: string) {
659+
return path?.split('/').map(encodeURI).join('/');
660+
}

src/app/avatar/avatar.sample.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ <h4 class="sample-title">Square Avatars</h4>
6262

6363
<igx-avatar initials="AZ" size="medium"></igx-avatar>
6464

65-
<igx-avatar initials="AZ" size="large"></igx-avatar>
65+
<igx-avatar [src]="null" initials="AZ" size="large"></igx-avatar>
6666

6767
<igx-avatar src="assets/images/avatar/18.jpg" size="small"></igx-avatar>
6868

0 commit comments

Comments
 (0)