Skip to content

Commit 04445c8

Browse files
dcramerclaude
andauthored
fix: allow issue IDs to start with numbers (#365)
The parseIssueId regex was too restrictive and rejected valid issue IDs that start with numbers (e.g., "3R-AUTOMATION-SYSTEM-3"). Updated the regex to accept alphanumeric characters at the start of project codes. Also cleaned up duplicate tests while ensuring comprehensive coverage of all valid and invalid formats. Fixes MCP-SERVER-E9E Refs #317 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Claude <[email protected]>
1 parent bf48167 commit 04445c8

File tree

2 files changed

+40
-11
lines changed

2 files changed

+40
-11
lines changed

packages/mcp-server/src/internal/issue-helpers.test.ts

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,19 +101,47 @@ describe("extractIssueId", () => {
101101
});
102102

103103
describe("parseIssueId", () => {
104-
it("should remove trailing punctuation from issue ID", () => {
105-
expect(
106-
// trailing period and exclamation
107-
parseIssueId("CLOUDFLARE-MCP-41.!"),
108-
).toBe("CLOUDFLARE-MCP-41");
109-
});
104+
describe("cleaning", () => {
105+
it("should remove trailing punctuation", () => {
106+
expect(parseIssueId("CLOUDFLARE-MCP-41.!")).toBe("CLOUDFLARE-MCP-41");
107+
});
110108

111-
it("should not modify a clean issue ID", () => {
112-
expect(parseIssueId("CLOUDFLARE-MCP-41")).toBe("CLOUDFLARE-MCP-41");
109+
it("should remove special characters except dash and underscore", () => {
110+
expect(parseIssueId("ID_123-456!@#")).toBe("ID_123-456");
111+
});
113112
});
114113

115-
it("should remove special characters except dash and underscore", () => {
116-
expect(parseIssueId("ID_123-456!@#")).toBe("ID_123-456");
114+
describe("format validation", () => {
115+
it("should accept pure numeric issue IDs", () => {
116+
expect(parseIssueId("12345")).toBe("12345");
117+
});
118+
119+
it("should accept project-based IDs starting with letters", () => {
120+
expect(parseIssueId("PROJECT-123")).toBe("PROJECT-123");
121+
expect(parseIssueId("MCP-SERVER-E9E")).toBe("MCP-SERVER-E9E");
122+
});
123+
124+
it("should accept project-based IDs starting with numbers", () => {
125+
expect(parseIssueId("3R-3")).toBe("3R-3");
126+
expect(parseIssueId("3R-AUTOMATION-SYSTEM-3")).toBe(
127+
"3R-AUTOMATION-SYSTEM-3",
128+
);
129+
});
130+
131+
it("should throw error for invalid formats", () => {
132+
// Starting with hyphen
133+
expect(() => parseIssueId("-123")).toThrowError(
134+
/Invalid issue ID format/,
135+
);
136+
137+
// Ending with hyphen
138+
expect(() => parseIssueId("PROJECT-")).toThrowError(
139+
/Invalid issue ID format/,
140+
);
141+
142+
// Empty string after cleaning
143+
expect(() => parseIssueId("!!!")).toThrowError(/Invalid issue ID format/);
144+
});
117145
});
118146
});
119147

packages/mcp-server/src/internal/issue-helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ export function parseIssueId(issueId: string) {
8888

8989
// Validate against common Sentry issue ID patterns
9090
// Either numeric IDs or PROJECT-ABC123 format
91-
const validFormatRegex = /^(\d+|[A-Za-z][\w-]*-[A-Za-z0-9]+)$/;
91+
// Allow project codes to start with alphanumeric characters (including numbers)
92+
const validFormatRegex = /^(\d+|[A-Za-z0-9][\w-]*-[A-Za-z0-9]+)$/;
9293

9394
if (!validFormatRegex.test(finalIssueId)) {
9495
throw new Error(

0 commit comments

Comments
 (0)