Skip to content

Commit b0ee116

Browse files
committed
Remove legacy xlinkHref compat support
1 parent 114eb72 commit b0ee116

7 files changed

Lines changed: 117 additions & 125 deletions

File tree

src/core/compile/compile.spec.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14911,7 +14911,7 @@ describe("$compile", () => {
1491114911
expect($$sanitizeUri).toHaveBeenCalledWith($rootScope.testUrl, false);
1491214912
});
1491314913

14914-
it("should use $$sanitizeUri when working with svg and xlink-href", async () => {
14914+
it("should use $$sanitizeUri when working with svg href bindings", async () => {
1491514915
const $$sanitizeUri = jasmine
1491614916
.createSpy("$$sanitizeUri")
1491714917
.and.returnValue("https://clean.example.org");
@@ -14924,10 +14924,10 @@ describe("$compile", () => {
1492414924
$rootScope.testUrl = "https://bad.example.org";
1492514925

1492614926
const elementA = $compile(
14927-
"<svg><a xlink-href=\"{{ testUrl + 'aTag' }}\"></a></svg>",
14927+
"<svg><a href=\"{{ testUrl + 'aTag' }}\"></a></svg>",
1492814928
)($rootScope);
1492914929
await wait();
14930-
expect(elementA.querySelector("a").getAttribute("xlink-href")).toBe(
14930+
expect(elementA.querySelector("a").getAttribute("href")).toBe(
1493114931
"https://clean.example.org",
1493214932
);
1493314933
expect($$sanitizeUri).toHaveBeenCalledWith(
@@ -14936,12 +14936,12 @@ describe("$compile", () => {
1493614936
);
1493714937

1493814938
const elementImage = $compile(
14939-
"<svg><image xlink-href=\"{{ testUrl + 'imageTag' }}\"></image></svg>",
14939+
"<svg><image href=\"{{ testUrl + 'imageTag' }}\"></image></svg>",
1494014940
)($rootScope);
1494114941
await wait();
14942-
expect(
14943-
elementImage.querySelector("image").getAttribute("xlink-href"),
14944-
).toBe("https://clean.example.org");
14942+
expect(elementImage.querySelector("image").getAttribute("href")).toBe(
14943+
"https://clean.example.org",
14944+
);
1494514945
expect($$sanitizeUri).toHaveBeenCalledWith(
1494614946
`${$rootScope.testUrl}imageTag`,
1494714947
true,
@@ -14992,7 +14992,7 @@ describe("$compile", () => {
1499214992
$$sanitizeUri.calls.reset();
1499314993

1499414994
const ngHref = $compile(
14995-
'<svg><image ng-href="{{ testUrl }}" xlink:href=""></image></svg>',
14995+
'<svg><image ng-href="{{ testUrl }}"></image></svg>',
1499614996
)($rootScope);
1499714997
await wait();
1499814998
expect(ngHref.querySelector("image").getAttribute("href")).toBe(
@@ -15032,7 +15032,7 @@ describe("$compile", () => {
1503215032
);
1503315033

1503415034
const ngHrefInterpolated = $compile(
15035-
'<svg><image ng-href="{{ testUrl }}" xlink:href=""></image></svg>',
15035+
'<svg><image ng-href="{{ testUrl }}"></image></svg>',
1503615036
)($rootScope);
1503715037
$rootScope.testUrl = disallowedDataUrl;
1503815038
await wait();
@@ -15049,7 +15049,7 @@ describe("$compile", () => {
1504915049
);
1505015050
});
1505115051

15052-
it("should require a RESOURCE_URL context for href by if not on an anchor or image", async () => {
15052+
it("should not specially handle legacy xlink-href on unsupported svg elements", async () => {
1505315053
let error = [];
1505415054
module.decorator("$exceptionHandler", () => {
1505515055
return (exception, cause) => {
@@ -15062,7 +15062,7 @@ describe("$compile", () => {
1506215062
)($rootScope);
1506315063
$rootScope.testUrl = "https://bad.example.org";
1506415064
await wait();
15065-
expect(error[0]).toMatch(/insecurl/);
15065+
expect(error.length).toBe(0);
1506615066
});
1506715067
});
1506815068

src/core/compile/compile.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3752,19 +3752,6 @@ export class CompileProvider {
37523752
return SCE_CONTEXTS._MEDIA_URL;
37533753
}
37543754

3755-
if (attrNormalizedName === "xlinkHref") {
3756-
// Some xlink:href are okay, most aren't
3757-
if (nodeName === "image") {
3758-
return SCE_CONTEXTS._MEDIA_URL;
3759-
}
3760-
3761-
if (nodeName === "a") {
3762-
return SCE_CONTEXTS._URL;
3763-
}
3764-
3765-
return SCE_CONTEXTS._RESOURCE_URL;
3766-
}
3767-
37683755
if (
37693756
nodeName === "image" &&
37703757
(attrNormalizedName === "href" || attrNormalizedName === "ngHref")

src/directive/attrs/attrs.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,34 +93,23 @@ entries(ALIASED_ATTR).forEach(([ngAttr]) => {
9393
priority: 99, // it needs to run after the attributes are interpolated
9494
link(
9595
_scope: ng.Scope,
96-
element: Element,
96+
_element: Element,
9797
attr: Attributes & Record<string, string>,
9898
): void {
99-
let name = attrName;
100-
101-
if (
102-
attrName === "href" &&
103-
toString.call((element as Element & { href?: unknown }).href) ===
104-
"[object SVGAnimatedString]"
105-
) {
106-
name = "xlinkHref";
107-
attr.$attr[name] = "href";
108-
}
109-
11099
// We need to sanitize the url at least once, in case it is a constant
111100
// non-interpolated attribute.
112101
attr.$set(normalized, $sce.getTrustedMediaUrl(attr[normalized]));
113102

114103
attr.$observe<string>(normalized, (value) => {
115104
if (!value) {
116105
if (attrName === "href") {
117-
attr.$set(name, null);
106+
attr.$set(attrName, null);
118107
}
119108

120109
return;
121110
}
122111

123-
attr.$set(name, value);
112+
attr.$set(attrName, value);
124113
});
125114
},
126115
};

src/directive/ref/href.spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ describe("ngHref", () => {
116116

117117
if (isDefined(window.SVGElement)) {
118118
describe("SVGAElement", () => {
119-
it("should interpolate the expression and bind to xlink:href", async () => {
119+
it("should interpolate the expression and bind to href", async () => {
120120
element = $compile('<svg><a ng-href="some/{{id}}"></a></svg>')(
121121
$rootScope,
122122
);
@@ -129,7 +129,7 @@ describe("ngHref", () => {
129129
expect(child.getAttribute("href")).toEqual("some/1");
130130
});
131131

132-
it("should bind xlink:href even if no interpolation", async () => {
132+
it("should bind href even if no interpolation", async () => {
133133
element = $compile('<svg><a ng-href="http://server"></a></svg>')(
134134
$rootScope,
135135
);

src/directive/repeat/repeat.ts

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ type RepeatScope = ng.Scope &
3333
type RepeatClone = Node | Node[];
3434

3535
type RepeatBlock = {
36-
id: any;
37-
scope?: RepeatScope;
38-
clone?: RepeatClone;
36+
_id: any;
37+
_scope?: RepeatScope;
38+
_clone?: RepeatClone;
3939
};
4040

4141
type RepeatBlockMap = Record<string, RepeatBlock>;
@@ -67,13 +67,13 @@ export function ngRepeatDirective($animate: any): ng.Directive {
6767
}
6868

6969
function getBlockStart(block: RepeatBlock) {
70-
return Array.isArray(block.clone) ? block.clone[0] : block.clone;
70+
return Array.isArray(block._clone) ? block._clone[0] : block._clone;
7171
}
7272

7373
function getBlockEnd(block: RepeatBlock) {
74-
return Array.isArray(block.clone)
75-
? block.clone[block.clone.length - 1]
76-
: block.clone;
74+
return Array.isArray(block._clone)
75+
? block._clone[block._clone.length - 1]
76+
: block._clone;
7777
}
7878

7979
function normalizeCloneNodes(clone: unknown): RepeatClone {
@@ -259,7 +259,7 @@ export function ngRepeatDirective($animate: any): ng.Directive {
259259
nextBlockOrder[index] = block;
260260
} else if (nextBlockMap[trackById]) {
261261
values(nextBlockOrder).forEach((x: RepeatBlock | undefined) => {
262-
if (x && x.scope) lastBlockMap[x.id] = block;
262+
if (x && x._scope) lastBlockMap[x._id] = block;
263263
});
264264
throw ngRepeatMinErr(
265265
"dupes",
@@ -270,9 +270,9 @@ export function ngRepeatDirective($animate: any): ng.Directive {
270270
);
271271
} else {
272272
nextBlockOrder[index] = {
273-
id: trackById,
274-
scope: undefined,
275-
clone: undefined,
273+
_id: trackById,
274+
_scope: undefined,
275+
_clone: undefined,
276276
};
277277
nextBlockMap[trackById] = true;
278278
}
@@ -281,17 +281,17 @@ export function ngRepeatDirective($animate: any): ng.Directive {
281281
for (const blockKey in lastBlockMap) {
282282
block = lastBlockMap[blockKey];
283283
const blockNodes = getBlockNodes(
284-
Array.isArray(block.clone)
285-
? block.clone
286-
: [block.clone as Node],
284+
Array.isArray(block._clone)
285+
? block._clone
286+
: [block._clone as Node],
287287
);
288288

289289
elementsToRemove = getBlockStart(block) as Element;
290290

291291
if (hasAnimate && elementsToRemove) {
292292
$animate.leave(elementsToRemove);
293293
} else {
294-
block.scope?.$destroy();
294+
block._scope?.$destroy();
295295
removeBlockNodes(blockNodes);
296296
}
297297

@@ -303,7 +303,7 @@ export function ngRepeatDirective($animate: any): ng.Directive {
303303
}
304304

305305
if (hasAnimate && elementsToRemove) {
306-
block.scope?.$destroy();
306+
block._scope?.$destroy();
307307
}
308308
}
309309

@@ -313,8 +313,8 @@ export function ngRepeatDirective($animate: any): ng.Directive {
313313
value = collection[key];
314314
block = nextBlockOrder[index];
315315

316-
if (block.scope) {
317-
const existingClone = block.clone;
316+
if (block._scope) {
317+
const existingClone = block._clone;
318318

319319
if (!existingClone) {
320320
continue;
@@ -338,7 +338,7 @@ export function ngRepeatDirective($animate: any): ng.Directive {
338338
}
339339
previousNode = getBlockEnd(block);
340340
updateScope(
341-
block.scope,
341+
block._scope,
342342
index,
343343
valueIdentifier,
344344
value,
@@ -354,7 +354,7 @@ export function ngRepeatDirective($animate: any): ng.Directive {
354354
? normalizedClone
355355
: [normalizedClone];
356356

357-
block.scope = scope;
357+
block._scope = scope;
358358
const endNode = cloneNodes[cloneNodes.length - 1];
359359

360360
if (
@@ -371,10 +371,10 @@ export function ngRepeatDirective($animate: any): ng.Directive {
371371
}
372372

373373
previousNode = endNode;
374-
block.clone = normalizedClone;
375-
nextBlockMap[block.id] = block;
374+
block._clone = normalizedClone;
375+
nextBlockMap[block._id] = block;
376376
updateScope(
377-
block.scope,
377+
block._scope,
378378
index,
379379
valueIdentifier,
380380
value,

0 commit comments

Comments
 (0)