diff --git a/src/lib/icon/icon-registry.ts b/src/lib/icon/icon-registry.ts index f0f2a06e70c1..0ef799edca5d 100644 --- a/src/lib/icon/icon-registry.ts +++ b/src/lib/icon/icon-registry.ts @@ -201,7 +201,7 @@ export class MatIconRegistry { return observableOf(cloneSvg(cachedIcon)); } - return RxChain.from(this._loadSvgIconFromConfig(new SvgIconConfig(url))) + return RxChain.from(this._loadSvgIconFromConfig(new SvgIconConfig(safeUrl))) .call(doOperator, svg => this._cachedIconsByUrl.set(url!, svg)) .call(map, svg => cloneSvg(svg)) .result(); diff --git a/src/lib/icon/icon.spec.ts b/src/lib/icon/icon.spec.ts index 13ff507a24fc..b84adc46734e 100644 --- a/src/lib/icon/icon.spec.ts +++ b/src/lib/icon/icon.spec.ts @@ -1,4 +1,4 @@ -import {inject, async, TestBed} from '@angular/core/testing'; +import {inject, async, fakeAsync, tick, TestBed} from '@angular/core/testing'; import {SafeResourceUrl, DomSanitizer} from '@angular/platform-browser'; import {HttpModule, XHRBackend} from '@angular/http'; import {MockBackend} from '@angular/http/testing'; @@ -126,7 +126,7 @@ describe('MatIcon', () => { }); describe('Icons from URLs', () => { - it('should register icon URLs by name', () => { + it('should register icon URLs by name', fakeAsync(() => { iconRegistry.addSvgIcon('fluffy', trust('cat.svg')); iconRegistry.addSvgIcon('fido', trust('dog.svg')); @@ -153,7 +153,14 @@ describe('MatIcon', () => { svgElement = verifyAndGetSingleSvgChild(matIconElement); verifyPathChildElement(svgElement, 'woof'); expect(httpRequestUrls).toEqual(['dog.svg', 'cat.svg']); - }); + + // Assert that a registered icon can be looked-up by url. + iconRegistry.getSvgIconFromUrl(trust('cat.svg')).subscribe(element => { + verifyPathChildElement(element, 'meow'); + }); + + tick(); + })); it('should throw an error when using an untrusted icon url', () => { iconRegistry.addSvgIcon('fluffy', 'farm-set-1.svg');