Skip to content

Commit

Permalink
fix(core): fix page redirects comparison (#1563)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mister-Hope committed May 21, 2024
1 parent cf03532 commit 90a11d9
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions packages/core/src/app/prepare/prepareRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,15 @@ const resolvePageRedirects = ({ path, pathInferred }: Page): string[] => {
// paths that should redirect to this page, use set to dedupe
const redirectsSet = new Set<string>()

// add redirect to the set when the redirect could not be normalized & encoded to the page path
const addRedirect = (redirect: string): void => {
const normalizedPath = normalizeRoutePath(redirect)
if (normalizedPath === path) return

const encodedPath = encodeURI(normalizedPath)
if (encodedPath === path) return

redirectsSet.add(redirect)
}

// redirect from inferred path, notice that the inferred path is not uri-encoded
if (pathInferred !== null) {
addRedirect(encodeURI(pathInferred))
const normalizedPathInferred = normalizeRoutePath(pathInferred)
const encodedPathInferred = encodeURI(normalizedPathInferred)

// add redirect to the set when the redirect could not be normalized & encoded to the page path
if (normalizedPathInferred !== path && encodedPathInferred !== path) {
redirectsSet.add(encodedPathInferred)
}
}

return Array.from(redirectsSet)
Expand Down

0 comments on commit 90a11d9

Please sign in to comment.