Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#577960: [SXA] fixed middleware redirects #1431

Merged
merged 1 commit into from
Apr 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Our versioning strategy is as follows:

* `[sitecore-jss-nextjs]` Fix for Link component which throws error if field is undefined ([#1425](https://github.com/Sitecore/jss/pull/1425))
* `[templates/react]` Fix compilation error when developing react template in monorepo ([#1428](https://github.com/Sitecore/jss/pull/1428))
* `[sitecore-jss-nextjs]` Fix regex for middleware redirects ([#1431](https://github.com/Sitecore/jss/pull/1431))

## 21.1.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,14 @@ export class RedirectsMiddleware extends MiddlewareBase {

return redirects.length
? redirects.find((redirect: RedirectInfo) => {
const pattern = `/^/${redirect.pattern
.toLowerCase()
.replace(/^\/|\/$/g, '')
.replace(/^\^|\$$/g, '')}$/`;

return (
(regexParser(redirect.pattern.toLowerCase()).test(req.nextUrl.pathname.toLowerCase()) ||
regexParser(redirect.pattern.toLowerCase()).test(
(regexParser(pattern).test(req.nextUrl.pathname.toLowerCase()) ||
regexParser(pattern).test(
`/${req.nextUrl.locale}${req.nextUrl.pathname}`.toLowerCase()
)) &&
(redirect.locale
Expand Down