@remix-run/router 1.23.0-pre-v6.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/dist/utils.d.ts CHANGED
@@ -399,6 +399,7 @@ export declare function decodePath(value: string): string;
399
399
  * @private
400
400
  */
401
401
  export declare function stripBasename(pathname: string, basename: string): string | null;
402
+ export declare const isAbsoluteUrl: (url: string) => boolean;
402
403
  /**
403
404
  * Returns a resolved path object relative to the given pathname.
404
405
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remix-run/router",
3
- "version": "1.23.0-pre-v6.0",
3
+ "version": "1.23.1-pre-v6.0",
4
4
  "description": "Nested/Data-driven/Framework-agnostic Routing",
5
5
  "keywords": [
6
6
  "remix",
package/utils.ts CHANGED
@@ -1128,6 +1128,9 @@ export function stripBasename(
1128
1128
  return pathname.slice(startIndex) || "/";
1129
1129
  }
1130
1130
 
1131
+ const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
1132
+ export const isAbsoluteUrl = (url: string) => ABSOLUTE_URL_REGEX.test(url);
1133
+
1131
1134
  /**
1132
1135
  * Returns a resolved path object relative to the given pathname.
1133
1136
  *
@@ -1140,11 +1143,29 @@ export function resolvePath(to: To, fromPathname = "/"): Path {
1140
1143
  hash = "",
1141
1144
  } = typeof to === "string" ? parsePath(to) : to;
1142
1145
 
1143
- let pathname = toPathname
1144
- ? toPathname.startsWith("/")
1145
- ? toPathname
1146
- : resolvePathname(toPathname, fromPathname)
1147
- : fromPathname;
1146
+ let pathname: string;
1147
+ if (toPathname) {
1148
+ if (isAbsoluteUrl(toPathname)) {
1149
+ pathname = toPathname;
1150
+ } else {
1151
+ if (toPathname.includes("//")) {
1152
+ let oldPathname = toPathname;
1153
+ toPathname = toPathname.replace(/\/\/+/g, "/");
1154
+ warning(
1155
+ false,
1156
+ `Pathnames cannot have embedded double slashes - normalizing ` +
1157
+ `${oldPathname} -> ${toPathname}`
1158
+ );
1159
+ }
1160
+ if (toPathname.startsWith("/")) {
1161
+ pathname = resolvePathname(toPathname.substring(1), "/");
1162
+ } else {
1163
+ pathname = resolvePathname(toPathname, fromPathname);
1164
+ }
1165
+ }
1166
+ } else {
1167
+ pathname = fromPathname;
1168
+ }
1148
1169
 
1149
1170
  return {
1150
1171
  pathname,