Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/solid-apples-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: use hasOwn check when deep-setting object properties
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/form-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ export function deep_set(object, keys, value) {
check_prototype_pollution(key);

const is_array = /^\d+$/.test(keys[i + 1]);
const exists = key in current;
const exists = Object.hasOwn(current, key);
const inner = current[key];

if (exists && is_array !== Array.isArray(inner)) {
Expand Down
14 changes: 14 additions & 0 deletions packages/kit/src/runtime/form-utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { beforeAll, describe, expect, test } from 'vitest';
import {
BINARY_FORM_CONTENT_TYPE,
convert_formdata,
deep_set,
deserialize_binary_form,
serialize_binary_form,
split_path
Expand Down Expand Up @@ -243,3 +244,16 @@ describe('binary form serializer', () => {
expect(res.data).toEqual({ a: 1 });
});
});

describe('deep_set', () => {
test('always creates own property', () => {
const target = {};

deep_set(target, ['toString', 'property'], 'hello');

// @ts-ignore
expect(target.toString.property).toBe('hello');
// @ts-ignore
expect(Object.prototype.toString.property).toBeUndefined();
});
});
Loading