File tree Expand file tree Collapse file tree 2 files changed +11
-7
lines changed
Expand file tree Collapse file tree 2 files changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,7 @@ import type {
1010} from "types/next-types" ;
1111import type { InternalEvent , InternalResult } from "types/open-next" ;
1212import { emptyReadableStream , toReadableStream } from "utils/stream" ;
13- import { normalizePath } from "utils/normalize-path"
13+ import { normalizeRepeatedSlashes } from "utils/normalize-path"
1414
1515import { debug } from "../../adapters/logger" ;
1616import { handleLocaleRedirect , localizePath } from "./i18n" ;
@@ -267,15 +267,12 @@ function handleRepeatedSlashRedirect(
267267 event : InternalEvent ,
268268) : false | InternalResult {
269269 // Redirect `https://example.com//foo` to `https://example.com/foo`.
270- const url = new URL ( event . url ) ;
271- if ( url . pathname . match ( / ( \\ | \/ \/ ) / ) ) {
270+ if ( event . rawPath . match ( / ( \\ | \/ \/ ) / ) ) {
272271 return {
273272 type : event . type ,
274273 statusCode : 308 ,
275274 headers : {
276- Location : `${ url . protocol } //${ url . host } ${ normalizePath ( url . pathname ) } ${
277- url . search
278- } `,
275+ Location : normalizeRepeatedSlashes ( new URL ( event . url ) ) ,
279276 } ,
280277 body : emptyReadableStream ( ) ,
281278 isBase64Encoded : false ,
Original file line number Diff line number Diff line change 11import path from "node:path" ;
22
33export function normalizePath ( path : string ) {
4- return path . replace ( / \\ / g, "/" ) . replace ( / \/ \/ + / g, "/" ) ;
4+ return path . replace ( / \\ / g, "/" ) ;
5+ }
6+
7+ export function normalizeRepeatedSlashes ( url : URL ) {
8+ const urlNoQuery = url . host + url . pathname ;
9+ return `${ url . protocol } //${ urlNoQuery
10+ . replace ( / \\ / g, "/" )
11+ . replace ( / \/ \/ + / g, "/" ) } ${ url . search } `;
512}
613
714export function getMonorepoRelativePath ( relativePath = "../.." ) : string {
You can’t perform that action at this time.
0 commit comments