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
4 changes: 3 additions & 1 deletion admin/app/workspace/create/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export const WorkspaceCreateForm = () => {
getValues,
formState: { errors, isSubmitting, isValid },
} = useForm<IWorkspace>({ defaultValues, mode: "onChange" });
// derived values
const workspaceBaseURL = encodeURI(WEB_BASE_URL || window.location.origin + "/");
Comment on lines +41 to +42
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider improving URL handling robustness

The current implementation has several potential issues:

  1. The fallback to window.location.origin won't work during SSR
  2. No handling of trailing slashes could lead to double slashes in the final URL
  3. encodeURI might be unnecessary for the base URL and could cause issues with special characters

Consider this improved implementation:

- const workspaceBaseURL = encodeURI(WEB_BASE_URL || window.location.origin + "/");
+ const workspaceBaseURL = (WEB_BASE_URL || (typeof window !== 'undefined' ? window.location.origin : '')).replace(/\/?$/, '/');
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// derived values
const workspaceBaseURL = encodeURI(WEB_BASE_URL || window.location.origin + "/");
// derived values
const workspaceBaseURL = (WEB_BASE_URL || (typeof window !== 'undefined' ? window.location.origin : '')).replace(/\/?$/, '/');


const handleCreateWorkspace = async (formData: IWorkspace) => {
await workspaceService
Expand Down Expand Up @@ -124,7 +126,7 @@ export const WorkspaceCreateForm = () => {
<div className="flex flex-col gap-1">
<h4 className="text-sm text-custom-text-300">Set your workspace&apos;s URL</h4>
<div className="flex gap-0.5 w-full items-center rounded-md border-[0.5px] border-custom-border-200 px-3">
<span className="whitespace-nowrap text-sm text-custom-text-200">{WEB_BASE_URL}/</span>
<span className="whitespace-nowrap text-sm text-custom-text-200">{workspaceBaseURL}</span>
<Controller
control={control}
name="slug"
Expand Down
5 changes: 2 additions & 3 deletions admin/core/components/workspace/list-item.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { observer } from "mobx-react";
import Link from "next/link";
import { ExternalLink } from "lucide-react";
// helpers
import { Tooltip } from "@plane/ui";
Expand All @@ -20,7 +19,7 @@ export const WorkspaceListItem = observer(({ workspaceId }: TWorkspaceListItemPr

if (!workspace) return null;
return (
<Link
<a
key={workspaceId}
href={`${WEB_BASE_URL}/${encodeURIComponent(workspace.slug)}`}
target="_blank"
Comment on lines +22 to 25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add security attributes for external link

The external link should include security attributes to protect against potential security vulnerabilities.

 <a
   key={workspaceId}
   href={`${WEB_BASE_URL}/${encodeURIComponent(workspace.slug)}`}
   target="_blank"
+  rel="noopener noreferrer"
   className="group flex items-center justify-between p-4 gap-2.5 truncate border border-custom-border-200/70 hover:border-custom-border-200 hover:bg-custom-background-90 rounded-md"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
<a
key={workspaceId}
href={`${WEB_BASE_URL}/${encodeURIComponent(workspace.slug)}`}
target="_blank"
<a
key={workspaceId}
href={`${WEB_BASE_URL}/${encodeURIComponent(workspace.slug)}`}
target="_blank"
rel="noopener noreferrer"
className="group flex items-center justify-between p-4 gap-2.5 truncate border border-custom-border-200/70 hover:border-custom-border-200 hover:bg-custom-background-90 rounded-md"

Expand Down Expand Up @@ -77,6 +76,6 @@ export const WorkspaceListItem = observer(({ workspaceId }: TWorkspaceListItemPr
<div className="flex-shrink-0">
<ExternalLink size={14} className="text-custom-text-400 group-hover:text-custom-text-200" />
</div>
</Link>
</a>
);
});