Skip to content

Commit 291a87c

Browse files
jelbournandrewseguin
authored andcommitted
fix(icon): use SafeResourceUrl in getSvgIconFromUrl (#7535)
1 parent 650103d commit 291a87c

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/lib/icon/icon-registry.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ export class MatIconRegistry {
201201
return observableOf(cloneSvg(cachedIcon));
202202
}
203203

204-
return RxChain.from(this._loadSvgIconFromConfig(new SvgIconConfig(url)))
204+
return RxChain.from(this._loadSvgIconFromConfig(new SvgIconConfig(safeUrl)))
205205
.call(doOperator, svg => this._cachedIconsByUrl.set(url!, svg))
206206
.call(map, svg => cloneSvg(svg))
207207
.result();

src/lib/icon/icon.spec.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {inject, async, TestBed} from '@angular/core/testing';
1+
import {inject, async, fakeAsync, tick, TestBed} from '@angular/core/testing';
22
import {SafeResourceUrl, DomSanitizer} from '@angular/platform-browser';
33
import {HttpModule, XHRBackend} from '@angular/http';
44
import {MockBackend} from '@angular/http/testing';
@@ -126,7 +126,7 @@ describe('MatIcon', () => {
126126
});
127127

128128
describe('Icons from URLs', () => {
129-
it('should register icon URLs by name', () => {
129+
it('should register icon URLs by name', fakeAsync(() => {
130130
iconRegistry.addSvgIcon('fluffy', trust('cat.svg'));
131131
iconRegistry.addSvgIcon('fido', trust('dog.svg'));
132132

@@ -153,7 +153,14 @@ describe('MatIcon', () => {
153153
svgElement = verifyAndGetSingleSvgChild(matIconElement);
154154
verifyPathChildElement(svgElement, 'woof');
155155
expect(httpRequestUrls).toEqual(['dog.svg', 'cat.svg']);
156-
});
156+
157+
// Assert that a registered icon can be looked-up by url.
158+
iconRegistry.getSvgIconFromUrl(trust('cat.svg')).subscribe(element => {
159+
verifyPathChildElement(element, 'meow');
160+
});
161+
162+
tick();
163+
}));
157164

158165
it('should throw an error when using an untrusted icon url', () => {
159166
iconRegistry.addSvgIcon('fluffy', 'farm-set-1.svg');

0 commit comments

Comments
 (0)