Skip to content

Commit 0148cf2

Browse files
committed
fix(shared): preserve leading whitespace in pasted Codex callbacks
1 parent e56f520 commit 0148cf2

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

‎packages/shared/src/codexAuthHandoff.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,12 @@ describe("pasted Codex callback", () => {
8686
it("accepts a callback copied without its scheme", () => {
8787
expect(codexCallbackUrl(copied, redirectUri, state).toString()).toBe(callbackUrl);
8888
});
89+
it("accepts leading whitespace with or without a scheme", () => {
90+
expect(codexCallbackUrl(` \t\n${callbackUrl}`, redirectUri, state).toString()).toBe(
91+
callbackUrl,
92+
);
93+
expect(codexCallbackUrl(` \t\n${copied}`, redirectUri, state).toString()).toBe(callbackUrl);
94+
});
8995
it("still rejects a scheme-less callback for another address or sign-in", () => {
9096
expect(() =>
9197
codexCallbackUrl(copied.replace("127.0.0.1", "localhost"), redirectUri, state),

‎packages/shared/src/codexAuthHandoff.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,10 @@ export function codexAuthorizationRequest(value: string) {
5757

5858
export function codexCallbackUrl(value: string, redirectUri: string, state: string) {
5959
const expected = new URL(redirectUri);
60+
const pasted = value.trimStart();
6061
// Browsers can hide `http://` in the address bar, so a pasted callback may lack it.
6162
const callback = new URL(
62-
/^[a-z][a-z\d+.-]*:\/\//iu.test(value) ? value : `${expected.protocol}//${value}`,
63+
/^[a-z][a-z\d+.-]*:\/\//iu.test(pasted) ? pasted : `${expected.protocol}//${pasted}`,
6364
);
6465
const states = callback.searchParams.getAll("state");
6566
const codes = callback.searchParams.getAll("code");

0 commit comments

Comments
 (0)