@remix-run/router 0.0.0-experimental-d90c8fb3 → 0.0.0-experimental-e7ce8959

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v0.0.0-experimental-d90c8fb3
2
+ * @remix-run/router v0.0.0-experimental-e7ce8959
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -752,14 +752,14 @@ function matchRoutes(routes, locationArg, basename) {
752
752
  rankRouteBranches(branches);
753
753
  let matches = null;
754
754
  for (let i = 0; matches == null && i < branches.length; ++i) {
755
+ matches = matchRouteBranch(branches[i],
755
756
  // Incoming pathnames are generally encoded from either window.location
756
757
  // or from router.navigate, but we want to match against the unencoded
757
758
  // paths in the route definitions. Memory router locations won't be
758
759
  // encoded here but there also shouldn't be anything to decode so this
759
760
  // should be a safe operation. This avoids needing matchRoutes to be
760
761
  // history-aware.
761
- let decoded = decodePath(pathname);
762
- matches = matchRouteBranch(branches[i], decoded);
762
+ safelyDecodeURI(pathname));
763
763
  }
764
764
  return matches;
765
765
  }
@@ -1038,7 +1038,7 @@ function matchPath(pattern, pathname) {
1038
1038
  if (isOptional && !value) {
1039
1039
  memo[paramName] = undefined;
1040
1040
  } else {
1041
- memo[paramName] = (value || "").replace(/%2F/g, "/");
1041
+ memo[paramName] = safelyDecodeURIComponent(value || "", paramName);
1042
1042
  }
1043
1043
  return memo;
1044
1044
  }, {});
@@ -1090,14 +1090,22 @@ function compilePath(path, caseSensitive, end) {
1090
1090
  let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
1091
1091
  return [matcher, params];
1092
1092
  }
1093
- function decodePath(value) {
1093
+ function safelyDecodeURI(value) {
1094
1094
  try {
1095
- return value.split("/").map(v => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
1095
+ return decodeURI(value);
1096
1096
  } catch (error) {
1097
1097
  warning(false, "The URL path \"" + value + "\" could not be decoded because it is is a " + "malformed URL segment. This is probably due to a bad percent " + ("encoding (" + error + ")."));
1098
1098
  return value;
1099
1099
  }
1100
1100
  }
1101
+ function safelyDecodeURIComponent(value, paramName) {
1102
+ try {
1103
+ return decodeURIComponent(value);
1104
+ } catch (error) {
1105
+ warning(false, "The value for the URL param \"" + paramName + "\" will not be decoded because" + (" the string \"" + value + "\" is a malformed URL segment. This is probably") + (" due to a bad percent encoding (" + error + ")."));
1106
+ return value;
1107
+ }
1108
+ }
1101
1109
 
1102
1110
  /**
1103
1111
  * @private
@@ -3267,7 +3275,8 @@ function createStaticHandler(routes, opts) {
3267
3275
  }
3268
3276
  // Config driven behavior flags
3269
3277
  let future = _extends({
3270
- v7_relativeSplatPath: false
3278
+ v7_relativeSplatPath: false,
3279
+ v7_throwAbortReason: false
3271
3280
  }, opts ? opts.future : null);
3272
3281
  let dataRoutes = convertRoutesToDataRoutes(routes, mapRouteProperties, undefined, manifest);
3273
3282
 
@@ -3490,8 +3499,7 @@ function createStaticHandler(routes, opts) {
3490
3499
  requestContext
3491
3500
  });
3492
3501
  if (request.signal.aborted) {
3493
- let method = isRouteRequest ? "queryRoute" : "query";
3494
- throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3502
+ throwStaticHandlerAbortedError(request, isRouteRequest, future);
3495
3503
  }
3496
3504
  }
3497
3505
  if (isRedirectResult(result)) {
@@ -3609,8 +3617,7 @@ function createStaticHandler(routes, opts) {
3609
3617
  requestContext
3610
3618
  }))]);
3611
3619
  if (request.signal.aborted) {
3612
- let method = isRouteRequest ? "queryRoute" : "query";
3613
- throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3620
+ throwStaticHandlerAbortedError(request, isRouteRequest, future);
3614
3621
  }
3615
3622
 
3616
3623
  // Process and commit output from loaders
@@ -3655,6 +3662,13 @@ function getStaticContextFromError(routes, context, error) {
3655
3662
  });
3656
3663
  return newContext;
3657
3664
  }
3665
+ function throwStaticHandlerAbortedError(request, isRouteRequest, future) {
3666
+ if (future.v7_throwAbortReason && request.signal.reason !== undefined) {
3667
+ throw request.signal.reason;
3668
+ }
3669
+ let method = isRouteRequest ? "queryRoute" : "query";
3670
+ throw new Error(method + "() call aborted: " + request.method + " " + request.url);
3671
+ }
3658
3672
  function isSubmissionNavigation(opts) {
3659
3673
  return opts != null && ("formData" in opts && opts.formData != null || "body" in opts && opts.body !== undefined);
3660
3674
  }