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

Commit c9e6cf9

Browse files
feelepxyzlgalfaso
authored andcommitted
fix($compile): Fix namespace detection for achor elements
Closes: #13480
1 parent c7ed8a3 commit c9e6cf9

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/ng/compile.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1396,7 +1396,7 @@ function $CompileProvider($provide, $$sanitizeUriProvider) {
13961396
if (!node) {
13971397
return 'html';
13981398
} else {
1399-
return nodeName_(node) !== 'foreignobject' && node.toString().match(/SVG/) ? 'svg' : 'html';
1399+
return nodeName_(node) !== 'foreignobject' && toString.call(node).match(/SVG/) ? 'svg' : 'html';
14001400
}
14011401
}
14021402

src/ng/directive/ngInclude.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ var ngIncludeFillContentDirective = ['$compile',
281281
priority: -400,
282282
require: 'ngInclude',
283283
link: function(scope, $element, $attr, ctrl) {
284-
if (/SVG/.test($element[0].toString())) {
284+
if (toString.call($element[0]).match(/SVG/)) {
285285
// WebKit: https://bugs.webkit.org/show_bug.cgi?id=135698 --- SVG elements do not
286286
// support innerHTML, so detect this here and try to generate the contents
287287
// specially.

test/ng/compileSpec.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -360,7 +360,6 @@ describe('$compile', function() {
360360
});
361361
});
362362

363-
364363
describe('compile phase', function() {
365364

366365
it('should attach scope to the document node when it is compiled explicitly', inject(function($document) {
@@ -444,6 +443,15 @@ describe('$compile', function() {
444443
expect(element.html()).toBe("3");
445444
}));
446445

446+
it('should detect anchor elements with the string "SVG" in the `href` attribute as an anchor', inject(function($compile, $rootScope) {
447+
element = jqLite('<div><a href="/ID_SVG_ID">' +
448+
'<span ng-if="true">Should render</span>' +
449+
'</a></div>');
450+
$compile(element.contents())($rootScope);
451+
$rootScope.$digest();
452+
document.body.appendChild(element[0]);
453+
expect(element.find('span').text()).toContain('Should render');
454+
}));
447455

448456
describe('multiple directives per element', function() {
449457
it('should allow multiple directives per element', inject(function($compile, $rootScope, log) {

0 commit comments

Comments
 (0)