@remix-run/router 1.15.0 → 1.15.1-pre.0

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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # `@remix-run/router`
2
2
 
3
+ ## 1.15.1-pre.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Fix encoding/decoding issues with pre-encoded dynamic parameter values ([#11199](https://github.com/remix-run/react-router/pull/11199))
8
+
3
9
  ## 1.15.0
4
10
 
5
11
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.15.0
2
+ * @remix-run/router v1.15.1-pre.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -496,6 +496,10 @@ function getUrlBasedHistory(getLocation, createHref, validateLocation, options)
496
496
  // See https://bugzilla.mozilla.org/show_bug.cgi?id=878297
497
497
  let base = window.location.origin !== "null" ? window.location.origin : window.location.href;
498
498
  let href = typeof to === "string" ? to : createPath(to);
499
+ // Treating this as a full URL will strip any trailing spaces so we need to
500
+ // pre-encode them since they might be part of a matching splat param from
501
+ // an ancestor route
502
+ href = href.replace(/ $/, "%20");
499
503
  invariant(base, "No window.location.(origin|href) available to create URL for href: " + href);
500
504
  return new URL(href, base);
501
505
  }
@@ -752,14 +756,14 @@ function matchRoutes(routes, locationArg, basename) {
752
756
  rankRouteBranches(branches);
753
757
  let matches = null;
754
758
  for (let i = 0; matches == null && i < branches.length; ++i) {
755
- matches = matchRouteBranch(branches[i],
756
759
  // Incoming pathnames are generally encoded from either window.location
757
760
  // or from router.navigate, but we want to match against the unencoded
758
761
  // paths in the route definitions. Memory router locations won't be
759
762
  // encoded here but there also shouldn't be anything to decode so this
760
763
  // should be a safe operation. This avoids needing matchRoutes to be
761
764
  // history-aware.
762
- safelyDecodeURI(pathname));
765
+ let decoded = decodePath(pathname);
766
+ matches = matchRouteBranch(branches[i], decoded);
763
767
  }
764
768
  return matches;
765
769
  }
@@ -1038,7 +1042,7 @@ function matchPath(pattern, pathname) {
1038
1042
  if (isOptional && !value) {
1039
1043
  memo[paramName] = undefined;
1040
1044
  } else {
1041
- memo[paramName] = safelyDecodeURIComponent(value || "", paramName);
1045
+ memo[paramName] = (value || "").replace(/%2F/g, "/");
1042
1046
  }
1043
1047
  return memo;
1044
1048
  }, {});
@@ -1090,22 +1094,14 @@ function compilePath(path, caseSensitive, end) {
1090
1094
  let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
1091
1095
  return [matcher, params];
1092
1096
  }
1093
- function safelyDecodeURI(value) {
1097
+ function decodePath(value) {
1094
1098
  try {
1095
- return decodeURI(value);
1099
+ return value.split("/").map(v => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
1096
1100
  } catch (error) {
1097
1101
  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
1102
  return value;
1099
1103
  }
1100
1104
  }
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
- }
1109
1105
 
1110
1106
  /**
1111
1107
  * @private