Skip to content

Commit

Permalink
fix(next_core): align remove trailing slash (#57344)
Browse files Browse the repository at this point in the history
### What

minor fix to match behavior to https://github.com/vercel/next.js/blob/ae10b5c82b29b3b077378f05f75eb1b215b327f0/packages/next/src/shared/lib/router/utils/remove-trailing-slash.ts#L2C4-L9

as we're seeing a panic when route is /

```
Panic: PanicInfo { payload: Any { .. }, message: Some(byte index 1 is out of bounds of ``), location: Location { file: "packages/next-swc/crates/next-core/src/next_edge/route_regex.rs", line: 202, col: 59 }, can_unwind: true, force_no_backtrace: false }
Backtrace:    0: backtrace::backtrace::libunwind::trace
```

Closes WEB-1841
  • Loading branch information
kwonoj authored Oct 24, 2023
1 parent 7aef93d commit cad1200
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
11 changes: 10 additions & 1 deletion packages/next-swc/crates/next-core/src/next_edge/route_regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,17 @@ fn escape_string_regexp(segment: &str) -> String {
regex::escape(segment)
}

/// Removes the trailing slash for a given route or page path. Preserves the
/// root page. Examples:
/// - `/foo/bar/` -> `/foo/bar`
/// - `/foo/bar` -> `/foo/bar`
/// - `/` -> `/`
fn remove_trailing_slash(route: &str) -> &str {
route.trim_end_matches('/')
if route == "/" {
route
} else {
route.trim_end_matches('/')
}
}

static PARAM_MATCH_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"\[((?:\[.*\])|.+)\]").unwrap());
Expand Down
5 changes: 3 additions & 2 deletions test/turbopack-tests-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13408,14 +13408,15 @@
"Basics default setting with react 18 dev should contain dynamicIds in next data for dynamic imports",
"Basics default setting with react 18 dev should only render once in SSR",
"Basics default setting with react 18 dev useId() values should match on hydration",
"Concurrent mode in the experimental-edge runtime dev <RouteAnnouncer /> should not have the initial route announced",
"Concurrent mode in the experimental-edge runtime dev flushes styled-jsx styles as the page renders",
"Concurrent mode in the experimental-edge runtime dev should not have invalid config warning",
"Concurrent mode in the nodejs runtime dev <RouteAnnouncer /> should not have the initial route announced",
"Concurrent mode in the nodejs runtime dev flushes styled-jsx styles as the page renders",
"Concurrent mode in the nodejs runtime dev should not have invalid config warning"
],
"failed": [],
"failed": [
"Concurrent mode in the experimental-edge runtime dev <RouteAnnouncer /> should not have the initial route announced"
],
"pending": [
"Basics production mode default setting with react 18 prod hydrates correctly for normal page",
"Basics production mode default setting with react 18 prod no warnings for image related link props",
Expand Down

0 comments on commit cad1200

Please sign in to comment.