diff --git a/.changeset/mighty-mugs-refuse.md b/.changeset/mighty-mugs-refuse.md new file mode 100644 index 000000000..806b7775c --- /dev/null +++ b/.changeset/mighty-mugs-refuse.md @@ -0,0 +1,5 @@ +--- +"frames.js": patch +--- + +fix: a "complete" URLObject in `target` should be left as it is diff --git a/packages/frames.js/src/core/utils.test.ts b/packages/frames.js/src/core/utils.test.ts index 20ee959ab..057dd4fcc 100644 --- a/packages/frames.js/src/core/utils.test.ts +++ b/packages/frames.js/src/core/utils.test.ts @@ -41,6 +41,18 @@ describe("generateTargetURL", () => { "http://test.com/test?test=test" ); }); + + it("generates a correct URL if target is an URL object with every compulsory property", () => { + // If the user passing in a URL object with all props required to + // construct a full URL, that means they want to go straight to + // there without modification. + const baseUrl = new URL("http://test.com"); + const target = new URL("http://another.com/test"); + + expect(generateTargetURL({ baseUrl, target }).toString()).toBe( + target.toString() + ); + }); }); describe("resolveBaseUrl", () => { diff --git a/packages/frames.js/src/core/utils.ts b/packages/frames.js/src/core/utils.ts index 2c1c1da49..d06a0b938 100644 --- a/packages/frames.js/src/core/utils.ts +++ b/packages/frames.js/src/core/utils.ts @@ -47,6 +47,14 @@ function isValidButtonAction(action: unknown): action is ButtonActions { return typeof action === "string" && action in buttonActionToCode; } +function isUrlObjectComplete(urlObject: UrlObject): boolean { + return ( + !!urlObject.host && + !!urlObject.protocol && + !!urlObject.pathname + ); +} + export function generateTargetURL({ baseUrl, target, @@ -59,6 +67,9 @@ export function generateTargetURL({ } if (typeof target === "object") { + if (isUrlObjectComplete(target)) { + return new URL(formatUrl(target)); + } return new URL( formatUrl({ host: baseUrl.host,