mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-11 19:04:30 +00:00
repair regexp routes
This commit is contained in:
@@ -335,7 +335,7 @@ function get_pattern(segments: Part[][], add_trailing_slash: boolean) {
|
|||||||
const path = segments.map(segment => {
|
const path = segments.map(segment => {
|
||||||
return segment.map(part => {
|
return segment.map(part => {
|
||||||
return part.dynamic
|
return part.dynamic
|
||||||
? part.qualifier || part.spread ? '(.+)' : '([^\\/]+?)'
|
? part.qualifier || (part.spread ? '(.+)' : '([^\\/]+?)')
|
||||||
: encodeURI(part.content.normalize())
|
: encodeURI(part.content.normalize())
|
||||||
.replace(/\?/g, '%3F')
|
.replace(/\?/g, '%3F')
|
||||||
.replace(/#/g, '%23')
|
.replace(/#/g, '%23')
|
||||||
|
|||||||
8
test/apps/basics/src/routes/[id([0-9]+)].svelte
Normal file
8
test/apps/basics/src/routes/[id([0-9]+)].svelte
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<script>
|
||||||
|
import { stores } from '@sapper/app';
|
||||||
|
const { page } = stores();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Regexp page {$page.params.id}</h1>
|
||||||
|
|
||||||
|
<a href="regexp/234">nested regexp route</a>
|
||||||
@@ -3,4 +3,6 @@
|
|||||||
const { page } = stores();
|
const { page } = stores();
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<h1>{$page.params.slug.toUpperCase()}</h1>
|
<h1>{$page.params.slug}</h1>
|
||||||
|
|
||||||
|
<a href="234">regexp route</a>
|
||||||
|
|||||||
6
test/apps/basics/src/routes/regexp/[id([0-9]+)].svelte
Normal file
6
test/apps/basics/src/routes/regexp/[id([0-9]+)].svelte
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
import { stores } from '@sapper/app';
|
||||||
|
const { page } = stores();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<h1>Nested regexp page {$page.params.id}</h1>
|
||||||
@@ -82,7 +82,7 @@ describe('basics', function() {
|
|||||||
|
|
||||||
assert.equal(
|
assert.equal(
|
||||||
await r.text('h1'),
|
await r.text('h1'),
|
||||||
'TEST-SLUG'
|
'test-slug'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -316,6 +316,22 @@ describe('basics', function() {
|
|||||||
assert.equal(await r.text('h1'), 'B page');
|
assert.equal(await r.text('h1'), 'B page');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('find regexp routes', async () => {
|
||||||
|
await r.load('/qwe');
|
||||||
|
await r.sapper.start();
|
||||||
|
|
||||||
|
assert.equal(await r.text('h1'), 'qwe');
|
||||||
|
|
||||||
|
await r.page.click('[href="234"]');
|
||||||
|
await r.wait();
|
||||||
|
|
||||||
|
assert.equal(await r.text('h1'), 'Regexp page 234');
|
||||||
|
|
||||||
|
await r.page.click('[href="regexp/234"]');
|
||||||
|
await r.wait();
|
||||||
|
assert.equal(await r.text('h1'), 'Nested regexp page 234');
|
||||||
|
});
|
||||||
|
|
||||||
it('runs server route handlers before page handlers, if they match', async () => {
|
it('runs server route handlers before page handlers, if they match', async () => {
|
||||||
const json = await get(`${r.base}/middleware`, {
|
const json = await get(`${r.base}/middleware`, {
|
||||||
headers: {
|
headers: {
|
||||||
|
|||||||
@@ -95,16 +95,15 @@ describe('manifest_data', () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
// this test broken
|
it('allows regex qualifiers', () => {
|
||||||
// it('allows regex qualifiers', () => {
|
const { pages } = create_manifest_data(path.join(__dirname, 'samples/qualifiers'));
|
||||||
// const { pages } = create_manifest_data(path.join(__dirname, 'samples/qualifiers'));
|
|
||||||
//
|
assert.deepEqual(pages.map(p => p.pattern), [
|
||||||
// assert.deepEqual(pages.map(p => p.pattern), [
|
/^\/([0-9-a-z]{3,})\/?$/,
|
||||||
// /^\/([0-9-a-z]{3,})\/?$/,
|
/^\/([a-z]{2})\/?$/,
|
||||||
// /^\/([a-z]{2})\/?$/,
|
/^\/([^\/]+?)\/?$/
|
||||||
// /^\/([^\/]+?)\/?$/
|
]);
|
||||||
// ]);
|
});
|
||||||
// });
|
|
||||||
|
|
||||||
it('sorts routes correctly', () => {
|
it('sorts routes correctly', () => {
|
||||||
const { pages } = create_manifest_data(path.join(__dirname, 'samples/sorting'));
|
const { pages } = create_manifest_data(path.join(__dirname, 'samples/sorting'));
|
||||||
|
|||||||
Reference in New Issue
Block a user