Skip to content

Node-based terminal manager for AI coding agents — tmux-backed terminals and parallel agent sessions as draggable nodes on an infinite pan/zoom canvas. macOS, Linux, and a browser Server Edition.

fix(github): the owner grammar refuses consecutive hyphens, in one definition

reviewa0332bd572c2
diff --git a/src/core/github/config.ts b/src/core/github/config.ts
index 8cb245574..2ea6ea1f4 100644
--- a/src/core/github/config.ts
+++ b/src/core/github/config.ts
@@ -4,8 +4,11 @@ import type {
GitHubConfigResult,
NormalisedProjectKanbanGitHub
} from '../../shared/github-issues'
+import { GITHUB_OWNER_PATTERN } from '../../shared/github-issue-ref'
-const OWNER = '[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?'
+// The shared login grammar, so a slug the board accepts is exactly one an issue reference accepts
+// (`github-issue-ref.config-agreement.test.ts`).
+const OWNER = GITHUB_OWNER_PATTERN
const REPOSITORY = '[A-Za-z0-9_.-]+'
const REPOSITORY_PATH = new RegExp(`^(${OWNER})/(${REPOSITORY})$`)
diff --git a/src/core/github/github-issue-ref.config-agreement.test.ts b/src/core/github/github-issue-ref.config-agreement.test.ts
index 2b6defc81..5c2d317d4 100644
--- a/src/core/github/github-issue-ref.config-agreement.test.ts
+++ b/src/core/github/github-issue-ref.config-agreement.test.ts
@@ -17,6 +17,8 @@ const CORPUS = [
'o/-r',
'-o/r',
'o-/r',
+ 'a--b/r',
+ 'a-b-c/r',
'o/r;rm',
'o/r`id`',
'o/r$(id)',
@@ -30,6 +32,12 @@ const CORPUS = [
]
describe('issue-reference grammar agrees with the board repository parser', () => {
+ it('both refuse an owner with consecutive hyphens (GitHub allows only single inner ones)', () => {
+ expect(parseGitHubRepository('a--b/r')).toBeNull()
+ expect(parseGitHubRepository('https://github.com/a--b/r.git')).toBeNull()
+ expect(parseGitHubRepository('a-b-c/r')).toBe('a-b-c/r')
+ })
+
it.each(CORPUS)('%j', (slug) => {
// `parseGitHubRepository` also accepts URLs and strips `.git`; compare only on the canonical
// `owner/repo` form it returns, which is what the renderer is handed as the project repository.
diff --git a/src/core/github/project-avatar.test.ts b/src/core/github/project-avatar.test.ts
index c8f497257..99e2d605c 100644
--- a/src/core/github/project-avatar.test.ts
+++ b/src/core/github/project-avatar.test.ts
@@ -92,6 +92,17 @@ describe('resolveProjectAvatarDataUrl', () => {
expect(dataUrl).toBe('data:image/png;base64,AQ==')
})
+ it('refuses an owner GitHub could not have issued, before any request', async () => {
+ let fetched = false
+ for (const owner of ['a--b', '-acme', 'acme-', '../x']) {
+ expect(await resolveProjectAvatarDataUrl({
+ owner,
+ fetchImpl: async () => { fetched = true; return userJson(AVATAR) }
+ })).toBeNull()
+ }
+ expect(fetched).toBe(false)
+ })
+
it('returns null when avatar_url is missing', async () => {
const dataUrl = await resolveProjectAvatarDataUrl({
owner: 'acme',
diff --git a/src/core/github/project-avatar.ts b/src/core/github/project-avatar.ts
index 6b188acf9..f71b3c299 100644
--- a/src/core/github/project-avatar.ts
+++ b/src/core/github/project-avatar.ts
@@ -1,13 +1,14 @@
import type { Project } from '../../shared/types'
import { fetchAvatarDataUrl } from './avatar-fetcher'
import { parseGitHubRepository } from './config'
+import { GITHUB_OWNER_PATTERN } from '../../shared/github-issue-ref'
const API_ORIGIN = 'https://api.github.com'
const API_VERSION = '2022-11-28'
const MAX_USER_JSON_BYTES = 64 * 1024
-// A GitHub login: same shape as config's OWNER. Validated before it ever reaches the URL path so a
+// A GitHub login: the one shared grammar. Validated before it ever reaches the URL path so a
// hostile project.json owner cannot escape `/users/{owner}` into another api.github.com route.
-const OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/
+const OWNER = new RegExp(`^${GITHUB_OWNER_PATTERN}$`)
async function boundedJson(response: Response): Promise<Record<string, unknown> | null> {
const length = Number(response.headers.get('content-length'))
diff --git a/src/shared/github-issue-ref.test.ts b/src/shared/github-issue-ref.test.ts
index 6f743ee3e..2f546ba92 100644
--- a/src/shared/github-issue-ref.test.ts
+++ b/src/shared/github-issue-ref.test.ts
@@ -42,6 +42,9 @@ const HOSTILE = [
'o/.#1',
'-o/r#1',
'o-/r#1',
+ // GitHub allows only SINGLE inner hyphens in a login.
+ 'a--b/r#1',
+ '---/r#1',
'o/-r#1',
'o//r#1',
'o/r/x#1',
diff --git a/src/shared/github-issue-ref.ts b/src/shared/github-issue-ref.ts
index a3ac1949e..7c6096437 100644
--- a/src/shared/github-issue-ref.ts
+++ b/src/shared/github-issue-ref.ts
@@ -32,7 +32,14 @@ export interface IssueRef {
number: number
}
-const OWNER = /^[A-Za-z0-9](?:[A-Za-z0-9-]{0,37}[A-Za-z0-9])?$/
+/**
+ * A GitHub login (user or organization): 1–39 characters, alphanumerics and SINGLE inner hyphens —
+ * no leading, trailing or consecutive hyphen. A hyphen must be followed by an alphanumeric (the
+ * lookahead), which is what refuses all three. Unanchored so it embeds in a slug pattern; the ONE
+ * definition — the board's repository parser and the avatar fetch in `core/github` read it too.
+ */
+export const GITHUB_OWNER_PATTERN = '[A-Za-z0-9](?:[A-Za-z0-9]|-(?=[A-Za-z0-9])){0,38}'
+const OWNER = new RegExp(`^${GITHUB_OWNER_PATTERN}$`)
const REPO = /^[A-Za-z0-9_.-]{1,100}$/
const NUMBER = /^[1-9][0-9]{0,9}$/
const MAX_ISSUE_NUMBER = 2 ** 31 - 1