[WEB-3797] fix: remove leading slash from URL to copy (#6890)

* fix: remove prefix slash if present

* chore: make use of URL class to generate a valid URL
This commit is contained in:
Aaryan Khandelwal
2025-04-08 15:22:23 +05:30
committed by GitHub
parent 27cec64c56
commit 37699362ad
9 changed files with 24 additions and 45 deletions

View File

@@ -86,8 +86,11 @@ export const copyTextToClipboard = async (text: string): Promise<void> => {
* await copyUrlToClipboard("issues/123") // copies "https://example.com/issues/123"
*/
export const copyUrlToClipboard = async (path: string) => {
const originUrl = typeof window !== "undefined" && window.location.origin ? window.location.origin : "";
await copyTextToClipboard(`${originUrl}/${path}`);
// get origin or default to empty string if not in browser
const originUrl = typeof window !== "undefined" ? window.location.origin : "";
// create URL object and ensure proper path formatting
const url = new URL(path, originUrl);
await copyTextToClipboard(url.toString());
};
/**