@remix-run/router 0.0.0-experimental-8bb3ffdf → 0.0.0-experimental-d90c8fb3

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-8bb3ffdf
2
+ * @remix-run/router v0.0.0-experimental-d90c8fb3
3
3
  *
4
4
  * Copyright (c) Remix Software Inc.
5
5
  *
@@ -754,14 +754,14 @@
754
754
  rankRouteBranches(branches);
755
755
  let matches = null;
756
756
  for (let i = 0; matches == null && i < branches.length; ++i) {
757
- matches = matchRouteBranch(branches[i],
758
757
  // Incoming pathnames are generally encoded from either window.location
759
758
  // or from router.navigate, but we want to match against the unencoded
760
759
  // paths in the route definitions. Memory router locations won't be
761
760
  // encoded here but there also shouldn't be anything to decode so this
762
761
  // should be a safe operation. This avoids needing matchRoutes to be
763
762
  // history-aware.
764
- safelyDecodeURI(pathname));
763
+ let decoded = decodePath(pathname);
764
+ matches = matchRouteBranch(branches[i], decoded);
765
765
  }
766
766
  return matches;
767
767
  }
@@ -891,7 +891,7 @@
891
891
  branches.sort((a, b) => a.score !== b.score ? b.score - a.score // Higher score first
892
892
  : compareIndexes(a.routesMeta.map(meta => meta.childrenIndex), b.routesMeta.map(meta => meta.childrenIndex)));
893
893
  }
894
- const paramRe = /^:\w+$/;
894
+ const paramRe = /^:[\w-]+$/;
895
895
  const dynamicSegmentValue = 3;
896
896
  const indexRouteValue = 2;
897
897
  const emptySegmentValue = 1;
@@ -981,7 +981,7 @@
981
981
  // Apply the splat
982
982
  return stringify(params[star]);
983
983
  }
984
- const keyMatch = segment.match(/^:(\w+)(\??)$/);
984
+ const keyMatch = segment.match(/^:([\w-]+)(\??)$/);
985
985
  if (keyMatch) {
986
986
  const [, key, optional] = keyMatch;
987
987
  let param = params[key];
@@ -1040,7 +1040,7 @@
1040
1040
  if (isOptional && !value) {
1041
1041
  memo[paramName] = undefined;
1042
1042
  } else {
1043
- memo[paramName] = safelyDecodeURIComponent(value || "", paramName);
1043
+ memo[paramName] = (value || "").replace(/%2F/g, "/");
1044
1044
  }
1045
1045
  return memo;
1046
1046
  }, {});
@@ -1063,7 +1063,7 @@
1063
1063
  let regexpSource = "^" + path.replace(/\/*\*?$/, "") // Ignore trailing / and /*, we'll handle it below
1064
1064
  .replace(/^\/*/, "/") // Make sure it has a leading /
1065
1065
  .replace(/[\\.*+^${}|()[\]]/g, "\\$&") // Escape special regex chars
1066
- .replace(/\/:(\w+)(\?)?/g, (_, paramName, isOptional) => {
1066
+ .replace(/\/:([\w-]+)(\?)?/g, (_, paramName, isOptional) => {
1067
1067
  params.push({
1068
1068
  paramName,
1069
1069
  isOptional: isOptional != null
@@ -1092,22 +1092,14 @@
1092
1092
  let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
1093
1093
  return [matcher, params];
1094
1094
  }
1095
- function safelyDecodeURI(value) {
1095
+ function decodePath(value) {
1096
1096
  try {
1097
- return decodeURI(value);
1097
+ return value.split("/").map(v => decodeURIComponent(v).replace(/\//g, "%2F")).join("/");
1098
1098
  } catch (error) {
1099
1099
  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 + ")."));
1100
1100
  return value;
1101
1101
  }
1102
1102
  }
1103
- function safelyDecodeURIComponent(value, paramName) {
1104
- try {
1105
- return decodeURIComponent(value);
1106
- } catch (error) {
1107
- 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 + ")."));
1108
- return value;
1109
- }
1110
- }
1111
1103
 
1112
1104
  /**
1113
1105
  * @private
@@ -4202,7 +4194,11 @@
4202
4194
  // Check between word boundaries instead of startsWith() due to the last
4203
4195
  // paragraph of https://httpwg.org/specs/rfc9110.html#field.content-type
4204
4196
  if (contentType && /\bapplication\/json\b/.test(contentType)) {
4205
- data = await result.json();
4197
+ if (result.body == null) {
4198
+ data = null;
4199
+ } else {
4200
+ data = await result.json();
4201
+ }
4206
4202
  } else {
4207
4203
  data = await result.text();
4208
4204
  }