Skip to content

Commit 70af4ca

Browse files
authored
fix: a "complete" URLObject in target should be left as it is (#529)
* fix: a "complete" URLObject in `target` should be left as it is
1 parent 505f64b commit 70af4ca

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

.changeset/mighty-mugs-refuse.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"frames.js": patch
3+
---
4+
5+
fix: a "complete" URLObject in `target` should be left as it is

packages/frames.js/src/core/utils.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,18 @@ describe("generateTargetURL", () => {
4141
"http://test.com/test?test=test"
4242
);
4343
});
44+
45+
it("generates a correct URL if target is an URL object with every compulsory property", () => {
46+
// If the user passing in a URL object with all props required to
47+
// construct a full URL, that means they want to go straight to
48+
// there without modification.
49+
const baseUrl = new URL("http://test.com");
50+
const target = new URL("http://another.com/test");
51+
52+
expect(generateTargetURL({ baseUrl, target }).toString()).toBe(
53+
target.toString()
54+
);
55+
});
4456
});
4557

4658
describe("resolveBaseUrl", () => {

packages/frames.js/src/core/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ function isValidButtonAction(action: unknown): action is ButtonActions {
4747
return typeof action === "string" && action in buttonActionToCode;
4848
}
4949

50+
function isUrlObjectComplete(urlObject: UrlObject): boolean {
51+
return (
52+
!!urlObject.host &&
53+
!!urlObject.protocol &&
54+
!!urlObject.pathname
55+
);
56+
}
57+
5058
export function generateTargetURL({
5159
baseUrl,
5260
target,
@@ -59,6 +67,9 @@ export function generateTargetURL({
5967
}
6068

6169
if (typeof target === "object") {
70+
if (isUrlObjectComplete(target)) {
71+
return new URL(formatUrl(target));
72+
}
6273
return new URL(
6374
formatUrl({
6475
host: baseUrl.host,

0 commit comments

Comments
 (0)