@remix-run/router 1.23.0 → 1.23.1-pre-v6.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.23.1-pre-v6.0
4
+
5
+ ### Patch Changes
6
+
7
+ - Normalize double-slashes in `resolvePath` ([#14537](https://github.com/remix-run/react-router/pull/14537))
8
+
3
9
  ## 1.23.0
4
10
 
5
11
  ### Minor Changes
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @remix-run/router v1.23.0
2
+ * @remix-run/router v1.23.1-pre-v6.0
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -1140,6 +1140,8 @@ function stripBasename(pathname, basename) {
1140
1140
  }
1141
1141
  return pathname.slice(startIndex) || "/";
1142
1142
  }
1143
+ const ABSOLUTE_URL_REGEX$1 = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1144
+ const isAbsoluteUrl = url => ABSOLUTE_URL_REGEX$1.test(url);
1143
1145
 
1144
1146
  /**
1145
1147
  * Returns a resolved path object relative to the given pathname.
@@ -1155,7 +1157,25 @@ function resolvePath(to, fromPathname) {
1155
1157
  search = "",
1156
1158
  hash = ""
1157
1159
  } = typeof to === "string" ? parsePath(to) : to;
1158
- let pathname = toPathname ? toPathname.startsWith("/") ? toPathname : resolvePathname(toPathname, fromPathname) : fromPathname;
1160
+ let pathname;
1161
+ if (toPathname) {
1162
+ if (isAbsoluteUrl(toPathname)) {
1163
+ pathname = toPathname;
1164
+ } else {
1165
+ if (toPathname.includes("//")) {
1166
+ let oldPathname = toPathname;
1167
+ toPathname = toPathname.replace(/\/\/+/g, "/");
1168
+ warning(false, "Pathnames cannot have embedded double slashes - normalizing " + (oldPathname + " -> " + toPathname));
1169
+ }
1170
+ if (toPathname.startsWith("/")) {
1171
+ pathname = resolvePathname(toPathname.substring(1), "/");
1172
+ } else {
1173
+ pathname = resolvePathname(toPathname, fromPathname);
1174
+ }
1175
+ }
1176
+ } else {
1177
+ pathname = fromPathname;
1178
+ }
1159
1179
  return {
1160
1180
  pathname,
1161
1181
  search: normalizeSearch(search),