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

Respect redirects to external url destinations #4579

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions contributors.yml
Expand Up @@ -62,6 +62,7 @@
- camiaei
- CanRau
- ccssmnn
- cephalization
- chaance
- chenc041
- chenxsan
Expand Down
13 changes: 13 additions & 0 deletions integration/redirects-test.ts
Expand Up @@ -144,6 +144,12 @@ test.describe("redirects", () => {
return <h1>Page 2</h1>
}
`,
[`app/routes/loader/external.js`]: js`
import { redirect } from "@remix-run/node";
export const loader = () => {
return redirect("https://www.google.com/");
}
`,
},
});

Expand Down Expand Up @@ -186,4 +192,11 @@ test.describe("redirects", () => {
// Loader called twice
await page.waitForSelector(`#count:has-text("3")`);
});

test("redirects to external URLs", async ({ page }) => {
let app = new PlaywrightFixture(appFixture, page);

await app.waitForNetworkAfter(() => app.goto("/loader/external"));
expect(app.page.url()).toBe("https://www.google.com/");
});
});
3 changes: 2 additions & 1 deletion packages/remix-server-runtime/router/utils.ts
Expand Up @@ -817,7 +817,8 @@ export function resolvePath(to: To, fromPathname = "/"): Path {
} = typeof to === "string" ? parsePath(to) : to;

let pathname = toPathname
? toPathname.startsWith("/")
? // we don't want to prepend the fromPathname on root or external toPathnames'
toPathname.startsWith("/") || toPathname.startsWith("http")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brophdawg11 do we want to accept other protocols? (app:// itunes:// ..)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah definitely. I did this in RR the way it's checked in Remix today which should account for other protocols: https://github.com/remix-run/react-router/pull/9590/files#diff-c6f085a772081501e6db2af3eee90b15fe7cd7c965d2f220c2a3c5c7772bc0c4R2568

? toPathname
: resolvePathname(toPathname, fromPathname)
: fromPathname;
Expand Down