mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-22 15:15:19 +00:00
handle value-less query string parameters - fixes #426
This commit is contained in:
@@ -66,8 +66,8 @@ function select_route(url: URL): Target {
|
|||||||
const query: Record<string, string | true> = {};
|
const query: Record<string, string | true> = {};
|
||||||
if (url.search.length > 0) {
|
if (url.search.length > 0) {
|
||||||
url.search.slice(1).split('&').forEach(searchParam => {
|
url.search.slice(1).split('&').forEach(searchParam => {
|
||||||
const [, key, value] = /([^=]+)=(.*)/.exec(searchParam);
|
const [, key, value] = /([^=]+)(?:=(.*))?/.exec(searchParam);
|
||||||
query[key] = value ? decodeURIComponent(value.replace(/\+/g, ' ')) : true;
|
query[key] = decodeURIComponent((value || '').replace(/\+/g, ' '));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
return { url, path, page, match, query };
|
return { url, path, page, match, query };
|
||||||
|
|||||||
@@ -16,6 +16,7 @@
|
|||||||
<a rel=prefetch class='{page === "blog" ? "selected" : ""}' href='blog'>blog</a>
|
<a rel=prefetch class='{page === "blog" ? "selected" : ""}' href='blog'>blog</a>
|
||||||
<a href="const">const</a>
|
<a href="const">const</a>
|
||||||
<a href="echo/page/encöded?message=hëllö+wörld">echo/page/encöded?message=hëllö+wörld</a>
|
<a href="echo/page/encöded?message=hëllö+wörld">echo/page/encöded?message=hëllö+wörld</a>
|
||||||
|
<a href="echo/page/empty?message">echo/page/empty?message</a>
|
||||||
|
|
||||||
<div class='hydrate-test'></div>
|
<div class='hydrate-test'></div>
|
||||||
|
|
||||||
|
|||||||
@@ -772,6 +772,24 @@ function run({ mode, basepath = '' }) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('accepts value-less query string parameter on server', () => {
|
||||||
|
return nightmare.goto(`${base}/echo/page/empty?message`)
|
||||||
|
.page.title()
|
||||||
|
.then(title => {
|
||||||
|
assert.equal(title, 'empty ()');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('accepts value-less query string parameter on client', () => {
|
||||||
|
return nightmare.goto(base).init()
|
||||||
|
.click('a[href="echo/page/empty?message"]')
|
||||||
|
.wait(100)
|
||||||
|
.page.title()
|
||||||
|
.then(title => {
|
||||||
|
assert.equal(title, 'empty ()');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('encodes req.params for server routes', () => {
|
it('encodes req.params for server routes', () => {
|
||||||
return nightmare.goto(`${base}/echo/server-route/encöded`)
|
return nightmare.goto(`${base}/echo/server-route/encöded`)
|
||||||
.page.title()
|
.page.title()
|
||||||
|
|||||||
Reference in New Issue
Block a user