Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit1c5a042

Browse files
authored
fix: include origin in support link (#16572)
Fixes:#15542
1 parent0149222 commit1c5a042

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import{includeOrigin}from"./MobileMenu";
2+
3+
constmockOrigin="https://example.com";
4+
5+
describe("support link",()=>{
6+
it("should include origin if target starts with '/'",()=>{
7+
(windowasunknownas{location:Partial<Location>}).location={
8+
origin:mockOrigin,
9+
};// Mock the location origin
10+
11+
expect(includeOrigin("/test")).toBe(`${mockOrigin}/test`);
12+
expect(includeOrigin("/path/to/resource")).toBe(
13+
`${mockOrigin}/path/to/resource`,
14+
);
15+
});
16+
17+
it("should return the target unchanged if it does not start with '/'",()=>{
18+
expect(includeOrigin(`${mockOrigin}/page`)).toBe(`${mockOrigin}/page`);
19+
expect(includeOrigin("../relative/path")).toBe("../relative/path");
20+
expect(includeOrigin("relative/path")).toBe("relative/path");
21+
});
22+
});

‎site/src/modules/dashboard/Navbar/MobileMenu.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,11 @@ const UserSettingsSub: FC<UserSettingsSubProps> = ({
307307
asChild
308308
className={cn(itemStyles.default,itemStyles.sub)}
309309
>
310-
<ahref={l.target}target="_blank"rel="noreferrer">
310+
<a
311+
href={includeOrigin(l.target)}
312+
target="_blank"
313+
rel="noreferrer"
314+
>
311315
{l.name}
312316
</a>
313317
</DropdownMenuItem>
@@ -318,3 +322,11 @@ const UserSettingsSub: FC<UserSettingsSubProps> = ({
318322
</Collapsible>
319323
);
320324
};
325+
326+
exportconstincludeOrigin=(target:string):string=>{
327+
if(target.startsWith("/")){
328+
constbaseUrl=window.location.origin;
329+
return`${baseUrl}${target}`;
330+
}
331+
returntarget;
332+
};

‎site/src/testHelpers/entities.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,11 @@ export const MockSupportLinks: TypesGen.LinkConfig[] = [
246246
"https://github.com/coder/coder/issues/new?labels=needs+grooming&body={CODER_BUILD_INFO}",
247247
icon:"",
248248
},
249+
{
250+
name:"Fourth link",
251+
target:"/icons",
252+
icon:"",
253+
},
249254
];
250255

251256
exportconstMockUpdateCheck:TypesGen.UpdateCheckResponse={

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp