Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix]Continuous optionals should not throw conflict error #7939

Merged
merged 8 commits into from Dec 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/six-ravens-attack.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': patch
---

[fix] continuous optionals should not throw conflict error
9 changes: 5 additions & 4 deletions packages/kit/src/core/sync/create_manifest_data/index.js
Expand Up @@ -486,10 +486,11 @@ function prevent_conflicts(routes) {
const matcher = split[i];
const next = split[i + 1];

permutations = [
...permutations.map((x) => x + next),
...permutations.map((x) => x + `<${matcher}>${next}`)
];
permutations = permutations.reduce((a, b) => {
a.push(b + next);
if (!(matcher === '*' && b.endsWith('//'))) a.push(b + `<${matcher}>${next}`);
return a;
}, /** @type {string[]} */ ([]));
}

for (const permutation of permutations) {
Expand Down
29 changes: 29 additions & 0 deletions packages/kit/src/core/sync/create_manifest_data/index.spec.js
Expand Up @@ -386,6 +386,35 @@ test('optional parameters', () => {
]);
});

test('nested optionals', () => {
const { nodes, routes } = create('samples/nested-optionals');
assert.equal(nodes.map(simplify_node), [
default_layout,
default_error,
{ component: 'samples/nested-optionals/[[a]]/[[b]]/+page.svelte' }
]);

assert.equal(routes.map(simplify_route), [
{
id: '/',
pattern: '/^/$/'
},
{
id: '/[[a]]/[[b]]',
pattern: '/^(?:/([^/]+))?(?:/([^/]+))?/?$/',
page: {
layouts: [0],
errors: [1],
leaf: nodes.findIndex((node) => node.component?.includes('/[[a]]/[[b]]'))
}
},
{
id: '/[[a]]',
pattern: '/^(?:/([^/]+))?/?$/'
}
]);
});

test('ignores files and directories with leading underscores', () => {
const { routes } = create('samples/hidden-underscore');

Expand Down