From d868270f1baf0fd5f2c5677691cc9c4e88b47d8f Mon Sep 17 00:00:00 2001 From: Alan Agius Date: Thu, 18 Jul 2024 09:44:05 +0000 Subject: [PATCH] fix(@angular/build): prevent redirection loop Added handling to ensure trailing slashes on static files do not disregard query strings. Closes #28071 (cherry picked from commit 6d6937587f8dfa95c951e775f97abde45710c8a6) --- .../build/src/tools/vite/middlewares/assets-middleware.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts b/packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts index d1e4101cc89a..9dd93e1df516 100644 --- a/packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts +++ b/packages/angular/build/src/tools/vite/middlewares/assets-middleware.ts @@ -87,7 +87,8 @@ export function createAngularAssetsMiddleware( if (!pathnameHasTrailingSlash) { for (const assetPath of assets.keys()) { if (pathname === assetPath.substring(0, assetPath.lastIndexOf('/'))) { - const location = req.url + '/'; + const { pathname, search, hash } = new URL(req.url, 'http://localhost'); + const location = [pathname, '/', search, hash].join(''); res.statusCode = 301; res.setHeader('Content-Type', 'text/html');