Skip to content

Commit c52430b

Browse files
only21milclaude
andcommitted
fix(gitlab): accept only merge request URLs the path parser can read
The reference check let `?` and `#` into the host and allowed one-segment or empty-segment repositories, so URLs like https://gitlab.com?x=/g/p/-/merge_requests/5 and https://gitlab.com/t3code/-/merge_requests/12 passed it while CHANGE_REQUEST_PATH returned null. The host now stops at `/?#`, and the repository needs at least two non-empty segments, matching the parser. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 6e9591e commit c52430b

2 files changed

Lines changed: 21 additions & 16 deletions

File tree

‎packages/source-control-gitlab/src/shared/definition.test.ts‎

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,26 @@ describe("GitLab change request URLs", () => {
3131
expect(parse("https://gitlab.com/t3code/-/merge_requests/12")).toBeNull();
3232
});
3333

34-
it("recognizes a merge request path only before any query or fragment", () => {
35-
expect(
36-
definition.isChangeRequestReference("https://gitlab.com/g/p?x=/-/merge_requests/5"),
37-
).toBe(false);
38-
expect(definition.isChangeRequestReference("https://gitlab.com/g/p#/-/merge_requests/5")).toBe(
39-
false,
40-
);
41-
expect(
42-
definition.isChangeRequestReference(
43-
"https://code.acme.test/a/b/c/-/merge_requests/7?tab=diffs",
44-
),
45-
).toBe(true);
46-
expect(
47-
definition.isChangeRequestReference("http://git.internal/a/b/c/-/merge_requests/7#note_1"),
48-
).toBe(true);
34+
it("recognizes only merge request URLs it can parse", () => {
35+
for (const url of [
36+
"https://gitlab.com/g/p?x=/-/merge_requests/5",
37+
"https://gitlab.com/g/p#/-/merge_requests/5",
38+
"https://gitlab.com?x=/g/p/-/merge_requests/5",
39+
"https://gitlab.com#/g/p/-/merge_requests/5",
40+
"https://gitlab.com/t3code/-/merge_requests/12",
41+
"https://gitlab.com/g//-/merge_requests/5",
42+
]) {
43+
expect(definition.isChangeRequestReference(url), url).toBe(false);
44+
expect(parse(url), url).toBeNull();
45+
}
46+
for (const url of [
47+
"https://code.acme.test/a/b/c/-/merge_requests/7?tab=diffs",
48+
"http://git.internal/a/b/c/-/merge_requests/7#note_1",
49+
"https://code.acme.test/a/b/c/-/merge_requests/7/diffs",
50+
]) {
51+
expect(definition.isChangeRequestReference(url), url).toBe(true);
52+
expect(parse(url), url).toMatchObject({ repository: "a/b/c", number: 7 });
53+
}
4954
});
5055

5156
it("builds merge request URLs below the repository", () => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { icon } from "./icon.ts";
1111

1212
const CHECKOUT_COMMAND = /^glab\s+mr\s+checkout\s+(.+)$/i;
1313
const CHANGE_REQUEST_REFERENCE =
14-
/^https?:\/\/[^/\s]+\/([^?#\s]+)\/-\/merge_requests\/(\d+)(?:[/?#].*)?$/i;
14+
/^https?:\/\/[^/?#\s]+\/[^/?#\s]+(?:\/[^/?#\s]+)+\/-\/merge_requests\/(\d+)(?:[/?#].*)?$/i;
1515

1616
// Self-managed GitLab runs on any hostname and nests projects in groups.
1717
const CHANGE_REQUEST_PATH = /^\/([^/]+(?:\/[^/]+)+)\/-\/merge_requests\/(\d+)(?:\/|$)/u;

0 commit comments

Comments
 (0)