primate 0.29.6 → 0.29.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "primate",
3
- "version": "0.29.6",
3
+ "version": "0.29.7",
4
4
  "description": "Polymorphic development platform",
5
5
  "homepage": "https://primatejs.com",
6
6
  "bugs": "https://github.com/primatejs/primate/issues",
@@ -3,15 +3,14 @@ import { from, valmap } from "rcompat/object";
3
3
  import { tryreturn } from "rcompat/async";
4
4
  import errors from "../errors.js";
5
5
 
6
- const deslash = url => url.replaceAll(/(?<!http:)\/{2,}/gu, _ => "/");
7
-
8
6
  const parse_body = (request, url) =>
9
7
  tryreturn(async _ => await Body.parse(request) ?? {})
10
8
  .orelse(error => errors.MismatchedBody.throw(url.pathname, error.message));
11
9
 
12
10
  export default dispatch => async original => {
13
11
  const { headers } = original;
14
- const url = new URL(deslash(globalThis.decodeURIComponent(original.url)));
12
+
13
+ const url = new URL(globalThis.decodeURIComponent(original.url));
15
14
  const cookies = headers.get("cookie");
16
15
  const body = await parse_body(original, url);
17
16
 
@@ -39,9 +39,11 @@ export default app => {
39
39
  is_method({ route, method, pathname }));
40
40
 
41
41
  const index = path => `${location.routes}${path === "/" ? "/index" : path}`;
42
+ // remove excess slashes
43
+ const deslash = url => url.replaceAll(/\/{2,}/gu, _ => "/");
42
44
 
43
45
  return ({ original: { method }, url }) => {
44
- const pathname = deroot(url.pathname);
46
+ const pathname = deroot(deslash(url.pathname));
45
47
  const route = find(method, pathname) ?? errors.NoRouteToPath
46
48
  .throw(method.toLowerCase(), pathname, index(pathname));
47
49
  return { ...route, path: to_path(route, pathname) };