Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
type ScreenplayParagraph,
serializeFdx,
} from "./lib/fdx";
import { feedbackRedirectUrl } from "./lib/feedback";
import { type DeviceIdentity, loadIdentity, renameIdentity } from "./lib/identity";
import { paginateScreenplay } from "./lib/pagination";
import { loadPanelPreferences, savePanelPreferences } from "./lib/panel_preferences";
Expand Down Expand Up @@ -528,7 +529,9 @@ function App({ config: configOverrides }: { config?: Partial<WriteConfig> } = {}
});
const result = (await response.json()) as { redirect_url?: string; error?: string };
if (!response.ok || !result.redirect_url) throw new Error(result.error || "Upload failed");
window.location.assign(result.redirect_url);
window.location.assign(
feedbackRedirectUrl(result.redirect_url, config.homepage, window.location.origin),
);
} catch {
setFeedbackStatus("error");
}
Expand Down
47 changes: 47 additions & 0 deletions app/src/lib/feedback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, expect, it } from "vitest";
import { feedbackRedirectUrl } from "./feedback";

describe("feedback redirect", () => {
it("resolves relative redirects against the Subscript homepage", () => {
expect(
feedbackRedirectUrl(
"/scripts/42/feedback?x=1",
"https://subscript.to",
"https://write.subscript.to",
),
).toBe("https://subscript.to/scripts/42/feedback?x=1");
});

it("moves redirects built from the editor host onto the Subscript homepage", () => {
expect(
feedbackRedirectUrl(
"https://write.subscript.to/scripts/42/feedback#top",
"https://subscript.to",
"https://write.subscript.to",
),
).toBe("https://subscript.to/scripts/42/feedback#top");
});

it("keeps redirects that already point at another origin", () => {
expect(
feedbackRedirectUrl(
"https://subscript.to/scripts/42",
"https://subscript.to",
"https://write.subscript.to",
),
).toBe("https://subscript.to/scripts/42");
expect(
feedbackRedirectUrl(
"https://auth.example.com/login",
"https://subscript.to",
"https://write.subscript.to",
),
).toBe("https://auth.example.com/login");
});

it("leaves redirects alone when the editor is embedded on the homepage", () => {
expect(feedbackRedirectUrl("/scripts/42", "https://subscript.to", "https://subscript.to")).toBe(
"https://subscript.to/scripts/42",
);
});
});
15 changes: 15 additions & 0 deletions app/src/lib/feedback.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Get Feedback must land on the canonical Subscript site, where SSO works,
// even when the editor is served from another host such as write.subscript.to.
export const feedbackRedirectUrl = (
redirectUrl: string,
homepage: string,
currentOrigin: string,
): string => {
const canonical = new URL(homepage);
const target = new URL(redirectUrl, canonical);
if (target.origin === currentOrigin && currentOrigin !== canonical.origin) {
target.protocol = canonical.protocol;
target.host = canonical.host;
}
return target.toString();
};
Loading