@remix-run/router 1.15.0 → 1.15.1

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/history.ts CHANGED
@@ -690,6 +690,10 @@ function getUrlBasedHistory(
690
690
  : window.location.href;
691
691
 
692
692
  let href = typeof to === "string" ? to : createPath(to);
693
+ // Treating this as a full URL will strip any trailing spaces so we need to
694
+ // pre-encode them since they might be part of a matching splat param from
695
+ // an ancestor route
696
+ href = href.replace(/ $/, "%20");
693
697
  invariant(
694
698
  base,
695
699
  `No window.location.(origin|href) available to create URL for href: ${href}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.15.0",
3
+ "version": "1.15.1",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/utils.ts CHANGED
@@ -485,16 +485,14 @@ export function matchRoutes<
485
485
 
486
486
  let matches = null;
487
487
  for (let i = 0; matches == null && i < branches.length; ++i) {
488
- matches = matchRouteBranch<string, RouteObjectType>(
489
- branches[i],
490
- // Incoming pathnames are generally encoded from either window.location
491
- // or from router.navigate, but we want to match against the unencoded
492
- // paths in the route definitions. Memory router locations won't be
493
- // encoded here but there also shouldn't be anything to decode so this
494
- // should be a safe operation. This avoids needing matchRoutes to be
495
- // history-aware.
496
- safelyDecodeURI(pathname)
497
- );
488
+ // Incoming pathnames are generally encoded from either window.location
489
+ // or from router.navigate, but we want to match against the unencoded
490
+ // paths in the route definitions. Memory router locations won't be
491
+ // encoded here but there also shouldn't be anything to decode so this
492
+ // should be a safe operation. This avoids needing matchRoutes to be
493
+ // history-aware.
494
+ let decoded = decodePath(pathname);
495
+ matches = matchRouteBranch<string, RouteObjectType>(branches[i], decoded);
498
496
  }
499
497
 
500
498
  return matches;
@@ -930,7 +928,7 @@ export function matchPath<
930
928
  if (isOptional && !value) {
931
929
  memo[paramName] = undefined;
932
930
  } else {
933
- memo[paramName] = safelyDecodeURIComponent(value || "", paramName);
931
+ memo[paramName] = (value || "").replace(/%2F/g, "/");
934
932
  }
935
933
  return memo;
936
934
  },
@@ -1002,9 +1000,12 @@ function compilePath(
1002
1000
  return [matcher, params];
1003
1001
  }
1004
1002
 
1005
- function safelyDecodeURI(value: string) {
1003
+ function decodePath(value: string) {
1006
1004
  try {
1007
- return decodeURI(value);
1005
+ return value
1006
+ .split("/")
1007
+ .map((v) => decodeURIComponent(v).replace(/\//g, "%2F"))
1008
+ .join("/");
1008
1009
  } catch (error) {
1009
1010
  warning(
1010
1011
  false,
@@ -1017,21 +1018,6 @@ function safelyDecodeURI(value: string) {
1017
1018
  }
1018
1019
  }
1019
1020
 
1020
- function safelyDecodeURIComponent(value: string, paramName: string) {
1021
- try {
1022
- return decodeURIComponent(value);
1023
- } catch (error) {
1024
- warning(
1025
- false,
1026
- `The value for the URL param "${paramName}" will not be decoded because` +
1027
- ` the string "${value}" is a malformed URL segment. This is probably` +
1028
- ` due to a bad percent encoding (${error}).`
1029
- );
1030
-
1031
- return value;
1032
- }
1033
- }
1034
-
1035
1021
  /**
1036
1022
  * @private
1037
1023
  */