Skip to content

Commit

Permalink
fix(icon): use SafeResourceUrl in getSvgIconFromUrl (#7535)
Browse files Browse the repository at this point in the history
  • Loading branch information
jelbourn authored and andrewseguin committed Oct 11, 2017
1 parent 650103d commit 291a87c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/lib/icon/icon-registry.ts
Expand Up @@ -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();
Expand Down
13 changes: 10 additions & 3 deletions 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';
Expand Down Expand Up @@ -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'));

Expand All @@ -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');
Expand Down

0 comments on commit 291a87c

Please sign in to comment.