From 4571561dd51b350bbe58e3af6c17ef0e53cd3dd7 Mon Sep 17 00:00:00 2001
From: Jeremy Elbourn
Date: Tue, 20 Dec 2016 22:05:19 -0800
Subject: [PATCH] fix(icon): remove svgSrc, only allow trusted urls (#1933)
* fix(icon): remove svgSrc, only allow trusted urls
* rxjs
---
src/demo-app/icon/icon-demo.html | 7 +-
src/demo-app/icon/icon-demo.ts | 9 +-
src/lib/icon/icon-registry.ts | 35 +++---
src/lib/icon/icon.spec.ts | 177 +++++++++++--------------------
src/lib/icon/icon.ts | 7 +-
tools/gulp/tasks/components.ts | 1 +
6 files changed, 90 insertions(+), 146 deletions(-)
diff --git a/src/demo-app/icon/icon-demo.html b/src/demo-app/icon/icon-demo.html
index 9cf76fd440e8..338c4717ff9f 100644
--- a/src/demo-app/icon/icon-demo.html
+++ b/src/demo-app/icon/icon-demo.html
@@ -3,11 +3,6 @@
These are some icons.
-
- From URL:
-
-
-
By name registered with MdIconProvider:
@@ -37,4 +32,4 @@
Custom icon font and CSS:
-
\ No newline at end of file
+
diff --git a/src/demo-app/icon/icon-demo.ts b/src/demo-app/icon/icon-demo.ts
index 8f6a1dc9f9b2..fac610e52c41 100644
--- a/src/demo-app/icon/icon-demo.ts
+++ b/src/demo-app/icon/icon-demo.ts
@@ -1,4 +1,5 @@
import {Component, ViewEncapsulation} from '@angular/core';
+import {DomSanitizer} from '@angular/platform-browser';
import {MdIconRegistry} from '@angular/material';
@Component({
@@ -10,10 +11,12 @@ import {MdIconRegistry} from '@angular/material';
encapsulation: ViewEncapsulation.None,
})
export class IconDemo {
- constructor(mdIconRegistry: MdIconRegistry) {
+ constructor(mdIconRegistry: MdIconRegistry, sanitizer: DomSanitizer) {
mdIconRegistry
- .addSvgIcon('thumb-up', '/icon/assets/thumbup-icon.svg')
- .addSvgIconSetInNamespace('core', '/icon/assets/core-icon-set.svg')
+ .addSvgIcon('thumb-up',
+ sanitizer.bypassSecurityTrustResourceUrl('/icon/assets/thumbup-icon.svg'))
+ .addSvgIconSetInNamespace('core',
+ sanitizer.bypassSecurityTrustResourceUrl('/icon/assets/core-icon-set.svg'))
.registerFontClassAlias('fontawesome', 'fa');
}
}
diff --git a/src/lib/icon/icon-registry.ts b/src/lib/icon/icon-registry.ts
index dcabdabcd3d7..1c9e449ea814 100644
--- a/src/lib/icon/icon-registry.ts
+++ b/src/lib/icon/icon-registry.ts
@@ -1,9 +1,11 @@
-import {Injectable} from '@angular/core';
+import {Injectable, SecurityContext} from '@angular/core';
+import {SafeResourceUrl, DomSanitizer} from '@angular/platform-browser';
import {Http} from '@angular/http';
import {MdError} from '../core';
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/observable/forkJoin';
import 'rxjs/add/observable/of';
+import 'rxjs/add/observable/throw';
import 'rxjs/add/operator/map';
import 'rxjs/add/operator/filter';
import 'rxjs/add/operator/do';
@@ -18,7 +20,7 @@ import 'rxjs/add/operator/catch';
*/
export class MdIconNameNotFoundError extends MdError {
constructor(iconName: string) {
- super(`Unable to find icon with the name "${iconName}"`);
+ super(`Unable to find icon with the name "${iconName}"`);
}
}
@@ -29,7 +31,7 @@ export class MdIconNameNotFoundError extends MdError {
*/
export class MdIconSvgTagNotFoundError extends MdError {
constructor() {
- super('