From 7cf9da066b38ba6b71df3fb860298b475599746d Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Mar 2022 14:20:28 -0400 Subject: [PATCH 1/5] rename validators to matchers --- documentation/docs/01-routing.md | 8 ++++---- packages/kit/src/core/build/build_server.js | 6 +++--- packages/kit/src/core/dev/plugin.js | 18 +++++++++--------- .../kit/src/core/generate_manifest/index.js | 10 +++++----- .../core/sync/create_manifest_data/index.js | 6 +++--- .../sync/create_manifest_data/index.spec.js | 6 +++--- packages/kit/src/core/sync/write_manifest.js | 2 +- packages/kit/src/core/sync/write_validators.js | 16 ++++++++-------- packages/kit/src/runtime/client/ambient.d.ts | 4 ++-- packages/kit/src/runtime/client/client.js | 6 +++--- packages/kit/src/runtime/client/parse.js | 6 +++--- packages/kit/src/runtime/server/endpoint.js | 2 +- packages/kit/src/runtime/server/index.js | 4 ++-- .../kit/src/runtime/server/page/load_node.js | 6 +++--- packages/kit/src/utils/routing.js | 10 +++++----- .../{validated => matched}/[fallback].svelte | 0 .../[letter=lowercase].svelte | 0 .../[letter=uppercase].svelte | 0 .../[number=numeric].svelte | 0 .../src/routes/routing/matched/__layout.svelte | 6 ++++++ .../src/routes/routing/matched/index.svelte | 1 + .../routes/routing/validated/__layout.svelte | 6 ------ .../src/routes/routing/validated/index.svelte | 1 - packages/kit/test/apps/basics/test/test.js | 14 +++++++------- packages/kit/types/index.d.ts | 4 ++-- packages/kit/types/internal.d.ts | 2 +- 26 files changed, 72 insertions(+), 72 deletions(-) rename packages/kit/test/apps/basics/src/routes/routing/{validated => matched}/[fallback].svelte (100%) rename packages/kit/test/apps/basics/src/routes/routing/{validated => matched}/[letter=lowercase].svelte (100%) rename packages/kit/test/apps/basics/src/routes/routing/{validated => matched}/[letter=uppercase].svelte (100%) rename packages/kit/test/apps/basics/src/routes/routing/{validated => matched}/[number=numeric].svelte (100%) create mode 100644 packages/kit/test/apps/basics/src/routes/routing/matched/__layout.svelte create mode 100644 packages/kit/test/apps/basics/src/routes/routing/matched/index.svelte delete mode 100644 packages/kit/test/apps/basics/src/routes/routing/validated/__layout.svelte delete mode 100644 packages/kit/test/apps/basics/src/routes/routing/validated/index.svelte diff --git a/documentation/docs/01-routing.md b/documentation/docs/01-routing.md index 64261b6bd3fc..3ff6184ea06d 100644 --- a/documentation/docs/01-routing.md +++ b/documentation/docs/01-routing.md @@ -318,14 +318,14 @@ A route can have multiple dynamic parameters, for example `src/routes/[category] > `src/routes/a/[...rest]/z.svelte` will match `/a/z` as well as `/a/b/z` and `/a/b/c/z` and so on. Make sure you check that the value of the rest parameter is valid. -#### Validation +#### Matching -A route like `src/routes/archive/[page]` would match `/archive/3`, but it would also match `/archive/potato`. We don't want that. You can ensure that route parameters are well-formed by adding a _validator_ — which takes the parameter string (`"3"` or `"potato"`) and returns `true` if it is valid — to your [`params`](/docs/configuration#files) directory... +A route like `src/routes/archive/[page]` would match `/archive/3`, but it would also match `/archive/potato`. We don't want that. You can ensure that route parameters are well-formed by adding a _matcher_ — which takes the parameter string (`"3"` or `"potato"`) and returns `true` if it is valid — to your [`params`](/docs/configuration#files) directory... ```js /// file: src/params/integer.js /** @type {import('@sveltejs/kit').ParamValidator} */ -export function validate(param) { +export function match(param) { return /^\d+$/.test(param); } ``` @@ -337,7 +337,7 @@ export function validate(param) { +src/routes/archive/[page=integer] ``` -If the pathname doesn't validate, SvelteKit will try to match other routes (using the sort order specified below), before eventually returning a 404. +If the pathname doesn't match, SvelteKit will try to match other routes (using the sort order specified below), before eventually returning a 404. #### Sorting diff --git a/packages/kit/src/core/build/build_server.js b/packages/kit/src/core/build/build_server.js index a7b4fc19bd4e..aa7224395e85 100644 --- a/packages/kit/src/core/build/build_server.js +++ b/packages/kit/src/core/build/build_server.js @@ -163,9 +163,9 @@ export async function build_server( input[name] = resolved; }); - // ...and every validator - Object.entries(manifest_data.validators).forEach(([key, file]) => { - const name = posixify(path.join('entries/validators', key)); + // ...and every matcher + Object.entries(manifest_data.matchers).forEach(([key, file]) => { + const name = posixify(path.join('entries/matchers', key)); input[name] = path.resolve(cwd, file); }); diff --git a/packages/kit/src/core/dev/plugin.js b/packages/kit/src/core/dev/plugin.js index be39bf2f036c..9a05216b9ba1 100644 --- a/packages/kit/src/core/dev/plugin.js +++ b/packages/kit/src/core/dev/plugin.js @@ -137,23 +137,23 @@ export async function create_plugin(config, cwd) { } }; }), - validators: async () => { - /** @type {Record} */ - const validators = {}; + matchers: async () => { + /** @type {Record} */ + const matchers = {}; - for (const key in manifest_data.validators) { - const file = manifest_data.validators[key]; + for (const key in manifest_data.matchers) { + const file = manifest_data.matchers[key]; const url = path.resolve(cwd, file); const module = await vite.ssrLoadModule(url); - if (module.validate) { - validators[key] = module.validate; + if (module.match) { + matchers[key] = module.match; } else { - throw new Error(`${file} does not export a \`validate\` function`); + throw new Error(`${file} does not export a \`match\` function`); } } - return validators; + return matchers; } } }; diff --git a/packages/kit/src/core/generate_manifest/index.js b/packages/kit/src/core/generate_manifest/index.js index ca071dee6a41..8f25b75c2bf6 100644 --- a/packages/kit/src/core/generate_manifest/index.js +++ b/packages/kit/src/core/generate_manifest/index.js @@ -58,7 +58,7 @@ export function generate_manifest({ build_data, relative_path, routes, format = /** @param {string} id */ const get_index = (id) => id && /** @type {LookupEntry} */ (bundled_nodes.get(id)).index; - const validators = new Set(); + const matchers = new Set(); // prettier-ignore return `{ @@ -75,7 +75,7 @@ export function generate_manifest({ build_data, relative_path, routes, format = const { pattern, names, types } = parse_route_id(route.id); types.forEach(type => { - if (type) validators.add(type); + if (type) matchers.add(type); }); if (route.type === 'page') { @@ -108,9 +108,9 @@ export function generate_manifest({ build_data, relative_path, routes, format = } }).filter(Boolean).join(',\n\t\t\t\t')} ], - validators: async () => { - ${Array.from(validators).map(type => `const { validate: ${type} } = await ${load(`${relative_path}/entries/validators/${type}.js`)}`).join('\n\t\t\t\t')} - return { ${Array.from(validators).join(', ')} }; + matchers: async () => { + ${Array.from(matchers).map(type => `const { match: ${type} } = await ${load(`${relative_path}/entries/matchers/${type}.js`)}`).join('\n\t\t\t\t')} + return { ${Array.from(matchers).join(', ')} }; } } }`.replace(/^\t/gm, ''); diff --git a/packages/kit/src/core/sync/create_manifest_data/index.js b/packages/kit/src/core/sync/create_manifest_data/index.js index cb5bf5a7dd76..64a34b6c9067 100644 --- a/packages/kit/src/core/sync/create_manifest_data/index.js +++ b/packages/kit/src/core/sync/create_manifest_data/index.js @@ -292,14 +292,14 @@ export default function create_manifest_data({ const params_base = path.relative(cwd, config.kit.files.params); /** @type {Record} */ - const validators = {}; + const matchers = {}; if (fs.existsSync(config.kit.files.params)) { for (const file of fs.readdirSync(config.kit.files.params)) { const ext = path.extname(file); const type = file.slice(0, -ext.length); if (/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(type)) { - validators[type] = path.join(params_base, file); + matchers[type] = path.join(params_base, file); } else { throw new Error( `Validator names must match /^[a-zA-Z_][a-zA-Z0-9_]*$/ — "${file}" is invalid` @@ -314,7 +314,7 @@ export default function create_manifest_data({ error, components, routes, - validators + matchers }; } diff --git a/packages/kit/src/core/sync/create_manifest_data/index.spec.js b/packages/kit/src/core/sync/create_manifest_data/index.spec.js index 0f8e295542d6..a4a014440541 100644 --- a/packages/kit/src/core/sync/create_manifest_data/index.spec.js +++ b/packages/kit/src/core/sync/create_manifest_data/index.spec.js @@ -532,10 +532,10 @@ test('errors on encountering an illegal __file', () => { ); }); -test('creates param validators', () => { - const { validators } = create('samples/basic'); // directory doesn't matter for the test +test('creates param matchers', () => { + const { matchers } = create('samples/basic'); // directory doesn't matter for the test - assert.equal(validators, { + assert.equal(matchers, { foo: path.join('params', 'foo.js'), bar: path.join('params', 'bar.js') }); diff --git a/packages/kit/src/core/sync/write_manifest.js b/packages/kit/src/core/sync/write_manifest.js index f859eaa46ae3..e27d94f1d4e3 100644 --- a/packages/kit/src/core/sync/write_manifest.js +++ b/packages/kit/src/core/sync/write_manifest.js @@ -45,7 +45,7 @@ export function write_manifest(manifest_data, base, output) { write_if_changed( `${output}/client-manifest.js`, trim(` - export { validators } from './client-validators.js'; + export { matchers } from './client-matchers.js'; export const components = ${components}; diff --git a/packages/kit/src/core/sync/write_validators.js b/packages/kit/src/core/sync/write_validators.js index b1b740c0b191..bd5e0d48805a 100644 --- a/packages/kit/src/core/sync/write_validators.js +++ b/packages/kit/src/core/sync/write_validators.js @@ -8,18 +8,18 @@ import { write_if_changed } from './utils.js'; */ export function write_validators(manifest_data, output) { const imports = []; - const validators = []; + const matchers = []; - for (const key in manifest_data.validators) { - const src = manifest_data.validators[key]; + for (const key in manifest_data.matchers) { + const src = manifest_data.matchers[key]; - imports.push(`import { validate as ${key} } from ${s(path.relative(output, src))};`); - validators.push(key); + imports.push(`import { match as ${key} } from ${s(path.relative(output, src))};`); + matchers.push(key); } const module = imports.length - ? `${imports.join('\n')}\n\nexport const validators = { ${validators.join(', ')} };` - : 'export const validators = {};'; + ? `${imports.join('\n')}\n\nexport const matchers = { ${matchers.join(', ')} };` + : 'export const matchers = {};'; - write_if_changed(`${output}/client-validators.js`, module); + write_if_changed(`${output}/client-matchers.js`, module); } diff --git a/packages/kit/src/runtime/client/ambient.d.ts b/packages/kit/src/runtime/client/ambient.d.ts index a49eaacea504..5f86e2fce7ef 100644 --- a/packages/kit/src/runtime/client/ambient.d.ts +++ b/packages/kit/src/runtime/client/ambient.d.ts @@ -1,5 +1,5 @@ declare module '__GENERATED__/client-manifest.js' { - import { CSRComponentLoader, ParamValidator } from 'types'; + import { CSRComponentLoader, ParamMatcher } from 'types'; /** * A list of all the layout/pages components used in the app @@ -12,5 +12,5 @@ declare module '__GENERATED__/client-manifest.js' { */ export const dictionary: Record; - export const validators: Record; + export const matchers: Record; } diff --git a/packages/kit/src/runtime/client/client.js b/packages/kit/src/runtime/client/client.js index 5b505cb0407c..1e4c99c535aa 100644 --- a/packages/kit/src/runtime/client/client.js +++ b/packages/kit/src/runtime/client/client.js @@ -15,12 +15,12 @@ import { import { parse } from './parse.js'; import Root from '__GENERATED__/root.svelte'; -import { components, dictionary, validators } from '__GENERATED__/client-manifest.js'; +import { components, dictionary, matchers } from '__GENERATED__/client-manifest.js'; const SCROLL_KEY = 'sveltekit:scroll'; const INDEX_KEY = 'sveltekit:index'; -const routes = parse(components, dictionary, validators); +const routes = parse(components, dictionary, matchers); // we import the root layout/error components eagerly, so that // connectivity errors after initialisation don't nuke the app @@ -660,7 +660,7 @@ export function create_client({ target, session, base, trailing_slash }) { // @ts-expect-error if (node.loaded.fallthrough) { throw new Error( - 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation' + 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation' ); } diff --git a/packages/kit/src/runtime/client/parse.js b/packages/kit/src/runtime/client/parse.js index 5f8eb4594d5f..294021924293 100644 --- a/packages/kit/src/runtime/client/parse.js +++ b/packages/kit/src/runtime/client/parse.js @@ -3,10 +3,10 @@ import { exec, parse_route_id } from '../../utils/routing.js'; /** * @param {import('types').CSRComponentLoader[]} components * @param {Record} dictionary - * @param {Record boolean>} validators + * @param {Record boolean>} matchers * @returns {import('types').CSRRoute[]} */ -export function parse(components, dictionary, validators) { +export function parse(components, dictionary, matchers) { const routes = Object.entries(dictionary).map(([id, [a, b, has_shadow]]) => { const { pattern, names, types } = parse_route_id(id); @@ -15,7 +15,7 @@ export function parse(components, dictionary, validators) { /** @param {string} path */ exec: (path) => { const match = pattern.exec(path); - if (match) return exec(match, names, types, validators); + if (match) return exec(match, names, types, matchers); }, a: a.map((n) => components[n]), b: b.map((n) => components[n]), diff --git a/packages/kit/src/runtime/server/endpoint.js b/packages/kit/src/runtime/server/endpoint.js index ff1b27180fa7..433d920612ad 100644 --- a/packages/kit/src/runtime/server/endpoint.js +++ b/packages/kit/src/runtime/server/endpoint.js @@ -72,7 +72,7 @@ export async function render_endpoint(event, mod) { // @ts-expect-error if (response.fallthrough) { throw new Error( - 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation' + 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching' ); } diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js index 5273bbbd5b9d..9768a99923f3 100644 --- a/packages/kit/src/runtime/server/index.js +++ b/packages/kit/src/runtime/server/index.js @@ -81,13 +81,13 @@ export async function respond(request, options, state) { } if (!state.prerender || !state.prerender.fallback) { - const validators = await options.manifest._.validators(); + const matchers = await options.manifest._.matchers(); for (const candidate of options.manifest._.routes) { const match = candidate.pattern.exec(decoded); if (!match) continue; - const matched = exec(match, candidate.names, candidate.types, validators); + const matched = exec(match, candidate.names, candidate.types, matchers); if (matched) { route = candidate; params = decode_params(matched); diff --git a/packages/kit/src/runtime/server/page/load_node.js b/packages/kit/src/runtime/server/page/load_node.js index ac3fa7cbfe98..96da0e4494ed 100644 --- a/packages/kit/src/runtime/server/page/load_node.js +++ b/packages/kit/src/runtime/server/page/load_node.js @@ -330,7 +330,7 @@ export async function load_node({ // @ts-expect-error if (loaded.fallthrough) { throw new Error( - 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation' + 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching' ); } } else if (shadow.body) { @@ -407,7 +407,7 @@ async function load_shadow_data(route, event, options, prerender) { // @ts-expect-error if (result.fallthrough) { throw new Error( - 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation' + 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching' ); } @@ -438,7 +438,7 @@ async function load_shadow_data(route, event, options, prerender) { // @ts-expect-error if (result.fallthrough) { throw new Error( - 'fallthrough is no longer supported. Use validators instead: https://kit.svelte.dev/docs/routing#advanced-routing-validation' + 'fallthrough is no longer supported. Use matchers instead: https://kit.svelte.dev/docs/routing#advanced-routing-matching' ); } diff --git a/packages/kit/src/utils/routing.js b/packages/kit/src/utils/routing.js index 39e7de9340cd..814f95813ca3 100644 --- a/packages/kit/src/utils/routing.js +++ b/packages/kit/src/utils/routing.js @@ -40,9 +40,9 @@ export function parse_route_id(key) { * @param {RegExpMatchArray} match * @param {string[]} names * @param {string[]} types - * @param {Record} validators + * @param {Record} matchers */ -export function exec(match, names, types, validators) { +export function exec(match, names, types, matchers) { /** @type {Record} */ const params = {}; @@ -52,10 +52,10 @@ export function exec(match, names, types, validators) { const value = match[i + 1] || ''; if (type) { - const validator = validators[type]; - if (!validator) throw new Error(`Missing "${type}" param validator`); // TODO do this ahead of time? + const matcher = matchers[type]; + if (!matcher) throw new Error(`Missing "${type}" param matcher`); // TODO do this ahead of time? - if (!validator(value)) return; + if (!matcher(value)) return; } params[name] = value; diff --git a/packages/kit/test/apps/basics/src/routes/routing/validated/[fallback].svelte b/packages/kit/test/apps/basics/src/routes/routing/matched/[fallback].svelte similarity index 100% rename from packages/kit/test/apps/basics/src/routes/routing/validated/[fallback].svelte rename to packages/kit/test/apps/basics/src/routes/routing/matched/[fallback].svelte diff --git a/packages/kit/test/apps/basics/src/routes/routing/validated/[letter=lowercase].svelte b/packages/kit/test/apps/basics/src/routes/routing/matched/[letter=lowercase].svelte similarity index 100% rename from packages/kit/test/apps/basics/src/routes/routing/validated/[letter=lowercase].svelte rename to packages/kit/test/apps/basics/src/routes/routing/matched/[letter=lowercase].svelte diff --git a/packages/kit/test/apps/basics/src/routes/routing/validated/[letter=uppercase].svelte b/packages/kit/test/apps/basics/src/routes/routing/matched/[letter=uppercase].svelte similarity index 100% rename from packages/kit/test/apps/basics/src/routes/routing/validated/[letter=uppercase].svelte rename to packages/kit/test/apps/basics/src/routes/routing/matched/[letter=uppercase].svelte diff --git a/packages/kit/test/apps/basics/src/routes/routing/validated/[number=numeric].svelte b/packages/kit/test/apps/basics/src/routes/routing/matched/[number=numeric].svelte similarity index 100% rename from packages/kit/test/apps/basics/src/routes/routing/validated/[number=numeric].svelte rename to packages/kit/test/apps/basics/src/routes/routing/matched/[number=numeric].svelte diff --git a/packages/kit/test/apps/basics/src/routes/routing/matched/__layout.svelte b/packages/kit/test/apps/basics/src/routes/routing/matched/__layout.svelte new file mode 100644 index 000000000000..a1283be99692 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/routing/matched/__layout.svelte @@ -0,0 +1,6 @@ +/routing/matched/a +/routing/matched/B +/routing/matched/1 +/routing/matched/everything-else + + diff --git a/packages/kit/test/apps/basics/src/routes/routing/matched/index.svelte b/packages/kit/test/apps/basics/src/routes/routing/matched/index.svelte new file mode 100644 index 000000000000..7460ed25bca2 --- /dev/null +++ b/packages/kit/test/apps/basics/src/routes/routing/matched/index.svelte @@ -0,0 +1 @@ +

Matchers

diff --git a/packages/kit/test/apps/basics/src/routes/routing/validated/__layout.svelte b/packages/kit/test/apps/basics/src/routes/routing/validated/__layout.svelte deleted file mode 100644 index c16a0128fb35..000000000000 --- a/packages/kit/test/apps/basics/src/routes/routing/validated/__layout.svelte +++ /dev/null @@ -1,6 +0,0 @@ -/routing/validated/a -/routing/validated/B -/routing/validated/1 -/routing/validated/everything-else - - diff --git a/packages/kit/test/apps/basics/src/routes/routing/validated/index.svelte b/packages/kit/test/apps/basics/src/routes/routing/validated/index.svelte deleted file mode 100644 index ddbd12a64e72..000000000000 --- a/packages/kit/test/apps/basics/src/routes/routing/validated/index.svelte +++ /dev/null @@ -1 +0,0 @@ -

Validators

diff --git a/packages/kit/test/apps/basics/test/test.js b/packages/kit/test/apps/basics/test/test.js index 4ff92dec3e5e..4fdf1b123cdb 100644 --- a/packages/kit/test/apps/basics/test/test.js +++ b/packages/kit/test/apps/basics/test/test.js @@ -2229,20 +2229,20 @@ test.describe.parallel('Static files', () => { }); }); -test.describe.parallel('Validators', () => { - test('Validates parameters', async ({ page, clicknav }) => { - await page.goto('/routing/validated'); +test.describe.parallel('Matchers', () => { + test('Matches parameters', async ({ page, clicknav }) => { + await page.goto('/routing/matched'); - await clicknav('[href="/routing/validated/a"]'); + await clicknav('[href="/routing/matched/a"]'); expect(await page.textContent('h1')).toBe('lowercase: a'); - await clicknav('[href="/routing/validated/B"]'); + await clicknav('[href="/routing/matched/B"]'); expect(await page.textContent('h1')).toBe('uppercase: B'); - await clicknav('[href="/routing/validated/1"]'); + await clicknav('[href="/routing/matched/1"]'); expect(await page.textContent('h1')).toBe('number: 1'); - await clicknav('[href="/routing/validated/everything-else"]'); + await clicknav('[href="/routing/matched/everything-else"]'); expect(await page.textContent('h1')).toBe('fallback: everything-else'); }); }); diff --git a/packages/kit/types/index.d.ts b/packages/kit/types/index.d.ts index 89ac690a0cff..b07fbee694f5 100644 --- a/packages/kit/types/index.d.ts +++ b/packages/kit/types/index.d.ts @@ -210,7 +210,7 @@ export interface Page = Record Promise>; + matchers: () => Promise>; }; } diff --git a/packages/kit/types/internal.d.ts b/packages/kit/types/internal.d.ts index 05222f29e665..c7be6de1b855 100644 --- a/packages/kit/types/internal.d.ts +++ b/packages/kit/types/internal.d.ts @@ -108,7 +108,7 @@ export interface ManifestData { error: string; components: string[]; routes: RouteData[]; - validators: Record; + matchers: Record; } export interface MethodOverride { From 129f56d56a69e4434ed81430a9db855b2be840e0 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Mar 2022 14:20:48 -0400 Subject: [PATCH 2/5] changeset --- .changeset/spicy-apples-return.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/spicy-apples-return.md diff --git a/.changeset/spicy-apples-return.md b/.changeset/spicy-apples-return.md new file mode 100644 index 000000000000..30e5276b712f --- /dev/null +++ b/.changeset/spicy-apples-return.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/kit': patch +--- + +[breaking] Rename validators to matchers From 4203ff7e20e19c25edb2f59e1dc31b1a7257ae8b Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Mar 2022 14:26:40 -0400 Subject: [PATCH 3/5] oops --- packages/kit/test/apps/basics/src/params/lowercase.js | 2 +- packages/kit/test/apps/basics/src/params/numeric.js | 2 +- packages/kit/test/apps/basics/src/params/uppercase.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/kit/test/apps/basics/src/params/lowercase.js b/packages/kit/test/apps/basics/src/params/lowercase.js index c0299c219f24..c9dc0695e69e 100644 --- a/packages/kit/test/apps/basics/src/params/lowercase.js +++ b/packages/kit/test/apps/basics/src/params/lowercase.js @@ -1,3 +1,3 @@ -export function validate(param) { +export function match(param) { return /^[a-z]+$/.test(param); } diff --git a/packages/kit/test/apps/basics/src/params/numeric.js b/packages/kit/test/apps/basics/src/params/numeric.js index 00ca87da0a38..2dfc26f3e5f9 100644 --- a/packages/kit/test/apps/basics/src/params/numeric.js +++ b/packages/kit/test/apps/basics/src/params/numeric.js @@ -1,3 +1,3 @@ -export function validate(param) { +export function match(param) { return !isNaN(param); } diff --git a/packages/kit/test/apps/basics/src/params/uppercase.js b/packages/kit/test/apps/basics/src/params/uppercase.js index d312f7643ab6..33ef1ba3543b 100644 --- a/packages/kit/test/apps/basics/src/params/uppercase.js +++ b/packages/kit/test/apps/basics/src/params/uppercase.js @@ -1,3 +1,3 @@ -export function validate(param) { +export function match(param) { return /^[A-Z]+$/.test(param); } From a46fd72553349ce0111310161e18dd730eb7d653 Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Mar 2022 14:41:23 -0400 Subject: [PATCH 4/5] fix docs --- documentation/docs/01-routing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/documentation/docs/01-routing.md b/documentation/docs/01-routing.md index 3ff6184ea06d..abe8056f1656 100644 --- a/documentation/docs/01-routing.md +++ b/documentation/docs/01-routing.md @@ -324,7 +324,7 @@ A route like `src/routes/archive/[page]` would match `/archive/3`, but it would ```js /// file: src/params/integer.js -/** @type {import('@sveltejs/kit').ParamValidator} */ +/** @type {import('@sveltejs/kit').ParamMatcher} */ export function match(param) { return /^\d+$/.test(param); } From a7dfbb2d36f90d524cfd6d7a8819c52f17709b8a Mon Sep 17 00:00:00 2001 From: Rich Harris Date: Wed, 16 Mar 2022 15:47:09 -0400 Subject: [PATCH 5/5] not sure how that snuck in there --- packages/kit/src/runtime/server/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/kit/src/runtime/server/index.js b/packages/kit/src/runtime/server/index.js index 9768a99923f3..ce6a8ca3e76f 100644 --- a/packages/kit/src/runtime/server/index.js +++ b/packages/kit/src/runtime/server/index.js @@ -60,7 +60,7 @@ export async function respond(request, options, state) { /** @type {Record} */ let params = {}; - if (options.paths.base) { + if (options.paths.base && !state.prerender?.fallback) { if (!decoded.startsWith(options.paths.base)) { return new Response(undefined, { status: 404 }); }