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/kind-seas-tell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@sveltejs/kit": patch
---

fix: restore invalid route error message during build process
12 changes: 10 additions & 2 deletions packages/kit/src/utils/routing.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { BROWSER } from 'esm-env';

const param_pattern = /^(\[)?(\.\.\.)?(\w+)(?:=(\w+))?(\])?$/;

/**
Expand Down Expand Up @@ -62,9 +64,15 @@ export function parse_route_id(id) {
);
}

// We know the match cannot be null because manifest generation would have
// if we hit an invalid param/matcher name with non-alphanumeric character.
// We know the match cannot be null in the browser because manifest generation
// would have invoked this during build and failed if we hit an invalid
// param/matcher name with non-alphanumeric character.
const match = /** @type {RegExpExecArray} */ (param_pattern.exec(content));
if (!BROWSER && !match) {
throw new Error(
`Invalid param: ${content}. Params and matcher names can only have underscores and alphanumeric characters.`
);
}

const [, is_optional, is_rest, name, matcher] = match;
// It's assumed that the following invalid route id cases are already checked
Expand Down