Skip to content

Commit

Permalink
remove uneeded else branch in matching empty paths
Browse files Browse the repository at this point in the history
  • Loading branch information
brophdawg11 committed Sep 29, 2022
1 parent 2aa1581 commit decf69b
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions packages/router/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,22 +639,15 @@ function compilePath(
regexpSource += "\\/*$";
} else if (path !== "" && path !== "/") {
// If our path is non-empty and contains anything beyond an initial slash,
// then we have _some_ form of path and we do not want to include the
// positive lookahead below, otherwise we incorrectly match things like
// /user-preferences for path /user. So, we look for an optional non-captured
// trailing slash (to match a portion of the URL) or the end of the path
// (if we've matched to the end). We used to do this with a word boundary
// but that gives false positives on routes like /user-preferences since
// `-` counts as a word boundary.
// then we have _some_ form of path in our regex so we should expect to
// match only if we find the end of this path segment. Look for an optional
// non-captured trailing slash (to match a portion of the URL) or the end
// of the path (if we've matched to the end). We used to do this with a
// word boundary but that gives false positives on routes like
// /user-preferences since `-` counts as a word boundary.
regexpSource += "(?:(?=\\/|$))";
} else {
// Otherwise, if we are an empty path, match a word boundary or a
// proceeding /. The word boundary restricts parent routes to matching only
// their own words and nothing more, e.g. parent route "/home" should not
// match "/home2". Additionally, allow paths starting with `.`, `-`, `~`,
// and url-encoded entities, but do not consume the character in the
// matched path so they can match against nested paths.
regexpSource += "(?:(?=[@.~-]|%[0-9A-F]{2})|\\b|\\/|$)";
// Nothing to match for "" or "/"
}

let matcher = new RegExp(regexpSource, caseSensitive ? undefined : "i");
Expand Down

0 comments on commit decf69b

Please sign in to comment.