Skip to content
Open
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/eleven-cases-guard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

fix: don't treat `Object.prototype` members as param matchers during validation
2 changes: 1 addition & 1 deletion packages/kit/src/utils/params.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function collect_matcher_names(routes) {
*/
export function validate_param_matchers(params, names, file) {
for (const name of names) {
if (!(name in params)) {
if (!Object.hasOwn(params, name)) {
throw new Error(`No matcher found for parameter '${name}'${file ? ` in ${file}` : ''}`);
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/kit/src/utils/params.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ test('validate_param_matchers throws for unknown matchers', () => {
);
});

test('validate_param_matchers ignores inherited properties', () => {
assert.throws(
() => validate_param_matchers({}, new Set(['toString']), 'params.js'),
/No matcher found for parameter 'toString'/
);
});

test('load_and_validate_params loads and validates params', async () => {
const params = await load_and_validate_params({
routes: [
Expand Down
Loading