Skip to content

Commit

Permalink
[fix] continuous optionals should not throw conflict error (#7939)
Browse files Browse the repository at this point in the history
fixes #7925
  • Loading branch information
aolose committed Dec 6, 2022
1 parent 2204cd8 commit a999fce
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
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

0 comments on commit a999fce

Please sign in to comment.