Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(inject): hasOwn instead of 'in' (fix #7284) #7460

Merged
merged 2 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core/instance/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { warn } from '../util/index'
import { hasSymbol } from 'core/util/env'
import { defineReactive, observerState } from '../observer/index'
import { hasOwn } from 'shared/util'

export function initProvide (vm: Component) {
const provide = vm.$options.provide
Expand Down Expand Up @@ -52,7 +53,7 @@ export function resolveInject (inject: any, vm: Component): ?Object {
const provideKey = inject[key].from
let source = vm
while (source) {
if (source._provided && provideKey in source._provided) {
if (source._provided && hasOwn(source._provided, provideKey)) {
result[key] = source._provided[provideKey]
break
}
Expand Down
12 changes: 12 additions & 0 deletions test/unit/features/options/inject.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -635,4 +635,16 @@ describe('Options provide/inject', () => {

expect(injected).toEqual('foo')
})

// #7284
it('should not inject prototype properties', () => {
const vm = new Vue({
provide: {}
})
new Vue({
parent: vm,
inject: ['constructor']
})
expect(`Injection "constructor" not found`).toHaveBeenWarned()
})
})