Skip to content
This repository was archived by the owner on Sep 5, 2024. It is now read-only.

Commit 1b37e82

Browse files
EmielHmmalerba
authored andcommitted
fix(icon): stop breaking SVGs that have id references (#11465)
<!-- Filling out this template is required! Do not delete it when submitting a Pull Request! Without this information, your Pull Request may be auto-closed. --> ## PR Checklist Please check that your PR fulfills the following requirements: - [X] The commit message follows [our guidelines](https://github.com/angular/material/blob/master/.github/CONTRIBUTING.md#-commit-message-format) - [X] Tests for the changes have been added or this is not a bug fix / enhancement - [X] Docs have been added, updated, or were not required ## PR Type What kind of change does this PR introduce? <!-- Please check the one that applies to this PR using "x". --> ``` [X] Bugfix [ ] Enhancement [ ] Documentation content changes [ ] Code style update (formatting, local variables) [ ] Refactoring (no functional changes, no api changes) [ ] Build related changes [ ] CI related changes [ ] Infrastructure changes [ ] Other... Please describe: ``` ## What is the current behavior? <!-- Please describe the current behavior that you are modifying and link to one or more relevant issues. --> When the same icon is used multiple times, they all have the same id. Issue Number: Fixes #11395. This fixes the issue found by @coennijhuis in PR #11342. ## What is the new behavior? When the same icon is used multiple times, they all have a different id. `_cache` followed by a number is appended to the id. ## Does this PR introduce a breaking change? ``` [ ] Yes [X] No ``` <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. --> <!-- Note that breaking changes are highly unlikely to get merged to master unless the validation is clear and the use case is critical. --> ## Other information
1 parent f44b271 commit 1b37e82

File tree

2 files changed

+8
-8
lines changed

2 files changed

+8
-8
lines changed

src/components/icon/icon.spec.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -456,17 +456,17 @@ describe('MdIcon service', function() {
456456
describe('$mdIcon() is passed an icon ID', function() {
457457

458458
it('should append configured SVG single icon', function() {
459-
var expected = updateDefaults('<svg><g id="android"></g></svg>');
459+
var expected = new RegExp(updateDefaults('<svg><g id="android_cache[0-9]+"></g></svg>'));
460460
$mdIcon('android').then(function(el) {
461-
expect(el.outerHTML).toEqual(expected);
461+
expect(el.outerHTML).toMatch(expected);
462462
});
463463
$scope.$digest();
464464
});
465465

466466
it('should append configured SVG icon from named group', function() {
467-
var expected = updateDefaults('<svg xmlns="http://www.w3.org/2000/svg"><g id="s1"></g></svg>');
467+
var expected = new RegExp(updateDefaults('<svg xmlns="http://www.w3.org/2000/svg"><g id="s1_cache[0-9]+"></g></svg>'));
468468
$mdIcon('social:s1').then(function(el) {
469-
expect(el.outerHTML).toEqual(expected);
469+
expect(el.outerHTML).toMatch(expected);
470470
});
471471
$scope.$digest();
472472
});
@@ -488,9 +488,9 @@ describe('MdIcon service', function() {
488488
});
489489

490490
it('should append configured SVG icon from default group', function() {
491-
var expected = updateDefaults('<svg xmlns="http://www.w3.org/2000/svg"><g id="c1"></g></svg>');
491+
var expected = new RegExp(updateDefaults('<svg xmlns="http://www.w3.org/2000/svg"><g id="c1_cache[0-9]+"></g></svg>'));
492492
$mdIcon('c1').then(function(el) {
493-
expect(el.outerHTML).toEqual(expected);
493+
expect(el.outerHTML).toMatch(expected);
494494
});
495495
$scope.$digest();
496496
});
@@ -514,7 +514,7 @@ describe('MdIcon service', function() {
514514

515515
it('should return correct SVG markup', function() {
516516
$mdIcon('android.svg').then(function(el) {
517-
expect(el.outerHTML).toEqual(updateDefaults('<svg><g id="android"></g></svg>'));
517+
expect(el.outerHTML).toMatch(new RegExp(updateDefaults('<svg><g id="android_cache[0-9]+"></g></svg>')));
518518
});
519519
$scope.$digest();
520520
});

src/components/icon/js/iconService.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ function MdIconService(config, $templateRequest, $q, $log, $mdUtil, $sce) {
577577
return function updateCache(icon) {
578578
iconCache[id] = isIcon(icon) ? icon : new Icon(icon, config[id]);
579579

580-
return iconCache[id].clone();
580+
return transformClone(iconCache[id]);
581581
};
582582
}
583583

0 commit comments

Comments
 (0)