Skip to content

Commit bb6579b

Browse files
committed
fix(issue-ref): do not read a URL fragment as owner/repo#12
The repository-qualified shape had no lookbehind in front of it, so any link whose path carried a segment before the `#` matched it as `<host>/<segment>#12`: `https://example.com/page#123` named issue #123, and the dispatch wrote a card for an issue nobody meant. The qualified shape now needs the same boundary as the bare number, so a URL fragment stays a fragment while `owner/repo#12`, a bare `#12` and a GitHub issue/pull URL still name the issue. Test: core/test/issue-ref-url-fragment.test.js (red on the base: 4/4). Docs-not-needed: the shape list in docs/subsystems/core-host.md is unchanged; this closes a hole in the rule the module and its tests already state (#1392), with no new module, contract or owned-path change.
1 parent 5e71a07 commit bb6579b

4 files changed

Lines changed: 66 additions & 4 deletions

File tree

‎core/src/shared/issue-ref.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// front makes it part of an identifier, a version, a hex colour or a URL fragment (`C#7`, `1.2#3`,
77
// `#3366ff`, `help/#123`), and a word character behind means the number keeps going (`#1360abc`).
88
// `owner/repo#12` is its own shape, tried separately, so this separation cannot swallow it: there
9-
// the `#` follows a repo name rather than a space.
10-
const ISSUE_REF = /(?<![\w./-])#(\d{1,7})(?![\w])|(?:github\.com\/)?([\w.-]+)\/([\w.-]+)#(\d{1,7})(?![\w])|github\.com\/([\w.-]+)\/([\w.-]+)\/(?:issues|pull)\/(\d{1,7})(?![\w])/gi
9+
// the `#` follows a repo name rather than a space. It needs the same boundary in front, or a URL
10+
// whose path has a segment before the `#` reads as that shape and names an issue nobody meant
11+
// (`https://example.com/page#123`, #1392).
12+
const ISSUE_REF = /(?<![\w./-])#(\d{1,7})(?![\w])|(?<![\w./-])(?:github\.com\/)?([\w.-]+)\/([\w.-]+)#(\d{1,7})(?![\w])|github\.com\/([\w.-]+)\/([\w.-]+)\/(?:issues|pull)\/(\d{1,7})(?![\w])/gi
1113

1214
// The id a match of `ISSUE_REF` names, normalised to `#1234`. The three shapes carry their number in
1315
// different groups (1, 4, 7); every reader takes it from here, so no caller can pick the wrong one.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// A URL fragment is not an issue reference (#1392). The repository-qualified shape
2+
// `owner/repo#12` has no lookbehind, so a link whose path carries a segment before the `#` read as
3+
// `<host>/<segment>#12` — `https://example.com/page#123` named issue #123 — and the dispatch wrote
4+
// a card for an issue nobody meant (#1360).
5+
import assert from 'node:assert/strict'
6+
import { test } from 'node:test'
7+
import { issueRefs, namesIssue } from '../src/shared/issue-ref.js'
8+
9+
const fragments = [
10+
'see https://example.com/page#123 for details',
11+
'https://example.com/docs/guide#12',
12+
'read https://docs.example.org/a/b#42 then',
13+
]
14+
15+
for (const text of fragments) {
16+
test(`a URL fragment is not an issue reference: ${text}`, () => {
17+
assert.deepEqual(issueRefs(text), [], text)
18+
})
19+
}
20+
21+
test('the shapes that name an issue keep working beside a URL', () => {
22+
assert.deepEqual(issueRefs('owner/repo#1360'), ['#1360'])
23+
assert.deepEqual(issueRefs('see owner/repo#1360 for the fix'), ['#1360'])
24+
assert.deepEqual(issueRefs('please rebase #1360 onto main'), ['#1360'])
25+
assert.deepEqual(issueRefs('https://github.com/o/r/issues/1360'), ['#1360'])
26+
assert.deepEqual(issueRefs('@Dev-2 rebase owner/repo#1360'), ['#1360'])
27+
assert.equal(namesIssue('https://example.com/docs/guide#12', 12), false)
28+
assert.equal(namesIssue('owner/repo#1360', 1360), true)
29+
})

‎patches/ds-bot/files/src/shared/issue-ref.js‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
// front makes it part of an identifier, a version, a hex colour or a URL fragment (`C#7`, `1.2#3`,
77
// `#3366ff`, `help/#123`), and a word character behind means the number keeps going (`#1360abc`).
88
// `owner/repo#12` is its own shape, tried separately, so this separation cannot swallow it: there
9-
// the `#` follows a repo name rather than a space.
10-
const ISSUE_REF = /(?<![\w./-])#(\d{1,7})(?![\w])|(?:github\.com\/)?([\w.-]+)\/([\w.-]+)#(\d{1,7})(?![\w])|github\.com\/([\w.-]+)\/([\w.-]+)\/(?:issues|pull)\/(\d{1,7})(?![\w])/gi
9+
// the `#` follows a repo name rather than a space. It needs the same boundary in front, or a URL
10+
// whose path has a segment before the `#` reads as that shape and names an issue nobody meant
11+
// (`https://example.com/page#123`, #1392).
12+
const ISSUE_REF = /(?<![\w./-])#(\d{1,7})(?![\w])|(?<![\w./-])(?:github\.com\/)?([\w.-]+)\/([\w.-]+)#(\d{1,7})(?![\w])|github\.com\/([\w.-]+)\/([\w.-]+)\/(?:issues|pull)\/(\d{1,7})(?![\w])/gi
1113

1214
// The id a match of `ISSUE_REF` names, normalised to `#1234`. The three shapes carry their number in
1315
// different groups (1, 4, 7); every reader takes it from here, so no caller can pick the wrong one.
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// A URL fragment is not an issue reference (#1392). The repository-qualified shape
2+
// `owner/repo#12` has no lookbehind, so a link whose path carries a segment before the `#` read as
3+
// `<host>/<segment>#12` — `https://example.com/page#123` named issue #123 — and the dispatch wrote
4+
// a card for an issue nobody meant (#1360).
5+
import assert from 'node:assert/strict'
6+
import { test } from 'node:test'
7+
import { issueRefs, namesIssue } from '../src/shared/issue-ref.js'
8+
9+
const fragments = [
10+
'see https://example.com/page#123 for details',
11+
'https://example.com/docs/guide#12',
12+
'read https://docs.example.org/a/b#42 then',
13+
]
14+
15+
for (const text of fragments) {
16+
test(`a URL fragment is not an issue reference: ${text}`, () => {
17+
assert.deepEqual(issueRefs(text), [], text)
18+
})
19+
}
20+
21+
test('the shapes that name an issue keep working beside a URL', () => {
22+
assert.deepEqual(issueRefs('owner/repo#1360'), ['#1360'])
23+
assert.deepEqual(issueRefs('see owner/repo#1360 for the fix'), ['#1360'])
24+
assert.deepEqual(issueRefs('please rebase #1360 onto main'), ['#1360'])
25+
assert.deepEqual(issueRefs('https://github.com/o/r/issues/1360'), ['#1360'])
26+
assert.deepEqual(issueRefs('@Dev-2 rebase owner/repo#1360'), ['#1360'])
27+
assert.equal(namesIssue('https://example.com/docs/guide#12', 12), false)
28+
assert.equal(namesIssue('owner/repo#1360', 1360), true)
29+
})

0 commit comments

Comments
 (0)