Skip to content

Commit 2dc529b

Browse files
tkuhemiyaclaude
andcommitted
fix(client): public hosts read their own page URLs only
Forgejo's page pattern runs on any hostname, so a GitLab clone URL whose group path contains `src/branch` was rewritten to the wrong repository. A URL on a known public host is now read only by that host's definition. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e09f34d commit 2dc529b

2 files changed

Lines changed: 16 additions & 9 deletions

File tree

‎packages/client-runtime/src/operations/projects.test.ts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ describe("add project shared logic", () => {
6666
expect(normalizePastedCloneUrl("https://gitlab.example.com/group/tree/main")).toBe(
6767
"https://gitlab.example.com/group/tree/main",
6868
);
69+
expect(normalizePastedCloneUrl("https://gitlab.com/team/platform/src/branch/repo.git")).toBe(
70+
"https://gitlab.com/team/platform/src/branch/repo.git",
71+
);
6972
});
7073

7174
it.each([

‎packages/source-control-core/src/shared/definition.ts‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,14 @@ export function makeSourceControlDefinitionRegistry(
708708
}
709709
return null;
710710
};
711+
const findByPublicDomain = (hostname: string) => {
712+
const host = hostname.toLowerCase();
713+
return definitions.find(
714+
(definition) =>
715+
definition.publicHost !== null &&
716+
(host === definition.publicHost || host.endsWith(`.${definition.publicHost}`)),
717+
);
718+
};
711719
return {
712720
definitions,
713721
get: (kind) =>
@@ -717,14 +725,7 @@ export function makeSourceControlDefinitionRegistry(
717725
const host = hostname.toLowerCase();
718726
return definitions.find((definition) => definition.publicHost === host);
719727
},
720-
findByPublicDomain: (hostname) => {
721-
const host = hostname.toLowerCase();
722-
return definitions.find(
723-
(definition) =>
724-
definition.publicHost !== null &&
725-
(host === definition.publicHost || host.endsWith(`.${definition.publicHost}`)),
726-
);
727-
},
728+
findByPublicDomain,
728729
parseChangeRequestUrl,
729730
parseCommitUrl: (value, kind) => {
730731
const url = httpUrl(value);
@@ -739,7 +740,10 @@ export function makeSourceControlDefinitionRegistry(
739740
repositoryUrlFromPageUrl: (value) => {
740741
const url = httpUrl(value);
741742
if (url === null) return null;
742-
for (const definition of claimOrder) {
743+
// Another host's any-hostname pattern can misread a public host's path, such as a GitLab
744+
// group named `src`, so a public host's URLs are read only by that host.
745+
const owner = findByPublicDomain(url.hostname);
746+
for (const definition of owner ? [owner] : claimOrder) {
743747
const repositoryUrl = definition.repositoryUrlFromPageUrl?.(url);
744748
if (repositoryUrl != null) return repositoryUrl;
745749
}

0 commit comments

Comments
 (0)