Skip to content

Commit a66b124

Browse files
committed
fix: use Vue public API and improve security
- Replace internal __v_isShallow with public isShallow API for Vue version compatibility - Fix hasOwnProperty usage in mergeReactiveObjects to prevent prototype pollution - Remove unnecessary no-op comment for cleaner code - Maintain all existing functionality while improving code quality
1 parent 819f21c commit a66b124

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

packages/pinia/src/store.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
markRaw,
1212
isRef,
1313
isReactive,
14+
isShallow,
1415
effectScope,
1516
EffectScope,
1617
ComputedRef,
@@ -89,14 +90,14 @@ function mergeReactiveObjects<
8990

9091
// no need to go through symbols because they cannot be serialized anyway
9192
for (const key in patchToApply) {
92-
if (!patchToApply.hasOwnProperty(key)) continue
93+
if (!Object.prototype.hasOwnProperty.call(patchToApply, key)) continue
9394
const subPatch = patchToApply[key]
9495
const targetValue = target[key]
9596

9697
if (
9798
isPlainObject(targetValue) &&
9899
isPlainObject(subPatch) &&
99-
target.hasOwnProperty(key) &&
100+
Object.prototype.hasOwnProperty.call(target, key) &&
100101
!isRef(subPatch) &&
101102
!isReactive(subPatch)
102103
) {
@@ -154,7 +155,7 @@ function isComputed(o: any): o is ComputedRef {
154155
* @returns true if the value is a shallowRef
155156
*/
156157
function isShallowRef(value: any): value is Ref {
157-
return isRef(value) && !!(value as any).__v_isShallow
158+
return isRef(value) && isShallow(value)
158159
}
159160

160161
function createOptionsStore<
@@ -525,8 +526,6 @@ function createSetupStore<
525526
pinia._e.run(() => (scope = effectScope()).run(() => setup({ action }))!)
526527
)!
527528

528-
// no-op: `$patch` inspects refs via `toRaw(store)`
529-
530529
// overwrite existing actions to support $onAction
531530
for (const key in setupStore) {
532531
const prop = setupStore[key]

0 commit comments

Comments
 (0)