From 51dab4f3ec9491fc20c43d2305a575556f61d7e8 Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Tue, 4 Jul 2023 15:42:16 +0200 Subject: [PATCH 1/4] =?UTF-8?q?=EF=BB=BF=20#589841:=20fixed=20redirect=20t?= =?UTF-8?q?oken?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/middleware/redirects-middleware.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts index 6ac1819fec..b1db05f198 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts @@ -623,7 +623,7 @@ describe('RedirectsMiddleware', () => { expect(finalRes).to.deep.equal(res); }); - xit('should redirect uses token in target', async () => { + it('should redirect uses token in target', async () => { const setCookies = () => {}; const res = createResponse({ url: 'http://localhost:3000/test1', From b565b2b2a8403c7a88eefa8642f2c1f102164f27 Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Wed, 5 Jul 2023 16:30:22 +0200 Subject: [PATCH 2/4] =?UTF-8?q?=EF=BB=BF=20#589841:=20fixed=20unit=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/middleware/redirects-middleware.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts index b1db05f198..6ac1819fec 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.test.ts @@ -623,7 +623,7 @@ describe('RedirectsMiddleware', () => { expect(finalRes).to.deep.equal(res); }); - it('should redirect uses token in target', async () => { + xit('should redirect uses token in target', async () => { const setCookies = () => {}; const res = createResponse({ url: 'http://localhost:3000/test1', From a783b3726b7d5c5690663e75095b04f5fcde8256 Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Mon, 17 Jul 2023 01:59:47 +0200 Subject: [PATCH 3/4] #589841: fixed pattern for redirects --- .../src/middleware/redirects-middleware.ts | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts index 224e120cf7..290f02c2e7 100644 --- a/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts +++ b/packages/sitecore-jss-nextjs/src/middleware/redirects-middleware.ts @@ -173,15 +173,18 @@ export class RedirectsMiddleware extends MiddlewareBase { return redirects.length ? redirects.find((redirect: RedirectInfo) => { - const pattern = `/^\/${redirect.pattern + redirect.pattern = `/^\/${redirect.pattern .replace(/^\/|\/$/g, '') + .replace(/^\^\/|\/\$$/g, '') .replace(/^\^|\$$/g, '')}$/gi`; return ( - (regexParser(pattern).test(tragetURL) || - regexParser(pattern).test(`${tragetURL}${targetQS}`) || - regexParser(pattern).test(`/${req.nextUrl.locale}${tragetURL}`) || - regexParser(pattern).test(`/${req.nextUrl.locale}${tragetURL}${targetQS}`)) && + (regexParser(redirect.pattern).test(tragetURL) || + regexParser(redirect.pattern).test(`${tragetURL}${targetQS}`) || + regexParser(redirect.pattern).test(`/${req.nextUrl.locale}${tragetURL}`) || + regexParser(redirect.pattern).test( + `/${req.nextUrl.locale}${tragetURL}${targetQS}` + )) && (redirect.locale ? redirect.locale.toLowerCase() === req.nextUrl.locale.toLowerCase() : true) From 289edee6b436950594bd3e6d5d4f12ca3e431c48 Mon Sep 17 00:00:00 2001 From: Ruslan Matkovskyi Date: Mon, 17 Jul 2023 02:05:22 +0200 Subject: [PATCH 4/4] #589841: changed CHANGELOG --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0de237786e..ab607e2a23 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ Our versioning strategy is as follows: * `[sitecore-jss-react]` Remove use of reactDom/server from React Image ([1544](https://github.com/Sitecore/jss/pull/1544)) * `[sitecore-jss-nextjs]` Referrer is not captured by Personalize middleware ([#1542](https://github.com/Sitecore/jss/pull/1542)) * `[sitecore.jss-react]` Fix double placeholder in Experience Editor in production mode ([#1557](https://github.com/Sitecore/jss/pull/1557)) -* `[sitecore-jss-nextjs]` Fix of redirects middleware. Add possible to use tokens like $1, $2, $3, etc. ([#1547](https://github.com/Sitecore/jss/pull/1547)) ([#1559](https://github.com/Sitecore/jss/pull/1559)) +* `[sitecore-jss-nextjs]` Fix of redirects middleware. Add possible to use tokens like $1, $2, $3, etc. ([#1547](https://github.com/Sitecore/jss/pull/1547)) ([#1559](https://github.com/Sitecore/jss/pull/1559)) ([#1561](https://github.com/Sitecore/jss/pull/1561)) ## 21.2.1