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

Commit fce42e0

Browse files
committed
fix($injector): do not use inherited $inject
Ensure that a function has its own $inject property, and not an inherited property, when annotating. This ensures that derived functions / classes do not get the dependencies of their super class. Fixes #15536
1 parent f768da2 commit fce42e0

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

src/auto/injector.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ function annotate(fn, strictDi, name) {
100100
last;
101101

102102
if (typeof fn === 'function') {
103-
if (!($inject = fn.$inject)) {
103+
$inject = fn.hasOwnProperty('$inject') ? fn.$inject : undefined;
104+
if (!$inject) {
104105
$inject = [];
105106
if (fn.length) {
106107
if (strictDi) {

test/auto/injectorSpec.js

+13
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ describe('injector', function() {
191191
});
192192

193193

194+
it('should not use inherited $inject', function() {
195+
function base() {}
196+
base.$inject = ['a'];
197+
function derived(b) {}
198+
if(Object.setPrototypeOf) {
199+
Object.setPrototypeOf(derived, base);
200+
} else {
201+
derived.__proto__ = base;
202+
}
203+
expect(annotate(derived)).toEqual(['b']);
204+
});
205+
206+
194207
it('should create $inject', function() {
195208
var extraParams = angular.noop;
196209
/* eslint-disable space-before-function-paren */

0 commit comments

Comments
 (0)