53ab8bcde1
Deep-copying route definition objects can break specific custom implementations of `$sce` (used to trust a `templateUrl` as RESOURCE_URL). The purpose of copying route definition objects was to guard against the user's modifying the route definition object after route registration, while still capturing inherited properties. As suggested by @IgorMinar in https://github.com/angular/angular.js/pull/14699#discussion_r66480539, we can achieve both _and_ support custom `$sce` implementations, by shallow-copying instead. This is an alternative implementation for #14699, which avoids the breaking change. Fixes #14478 Closes #14699 Closes #14750
29 lines
553 B
JavaScript
29 lines
553 B
JavaScript
'use strict';
|
|
|
|
/* global shallowCopy: true */
|
|
|
|
/**
|
|
* Creates a shallow copy of an object, an array or a primitive.
|
|
*
|
|
* Assumes that there are no proto properties for objects.
|
|
*/
|
|
function shallowCopy(src, dst) {
|
|
if (isArray(src)) {
|
|
dst = dst || [];
|
|
|
|
for (var i = 0, ii = src.length; i < ii; i++) {
|
|
dst[i] = src[i];
|
|
}
|
|
} else if (isObject(src)) {
|
|
dst = dst || {};
|
|
|
|
for (var key in src) {
|
|
if (!(key.charAt(0) === '$' && key.charAt(1) === '$')) {
|
|
dst[key] = src[key];
|
|
}
|
|
}
|
|
}
|
|
|
|
return dst || src;
|
|
}
|