Skip to content

Commit 59b2bb5

Browse files
authored
fix: keep summary when it contains CVE-ID (#41)
Anchor the CVE-ID regex to the start of the line so a summary such as "deps: CVE-ID: CVE-2024-1234 fix" is kept as the summary instead of only setting cveId. Leading whitespace stays optional, so unindented CVE-ID trailers still match.
1 parent d723f86 commit 59b2bb5

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

‎commit-stream.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default function commitStream (ghUser, ghProject) {
9797
null
9898
) {
9999
(commit.reviewers ??= []).push({ name: m[1], email: m[2] })
100-
} else if ((m = line.match(/\bCVE-ID:\s+(CVE-\d{4}-\d{4,})\b/)) !== null) {
100+
} else if ((m = line.match(/^\s*CVE-ID:\s+(CVE-\d{4}-\d{4,})\b/)) !== null) {
101101
commit.cveId = m[1]
102102
} else if ((m = line.match(/^\s+PR(?:[- ]?URL)?:\s*(.+)\s*$/) || line.match(/\(#(\d+)\)$/)) !== null) {
103103
commit.prUrl = m[1]

‎test.js‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,36 @@ test('cve id with 4 or more sequence digits', async () => {
234234
assert.deepStrictEqual(commits.map((c) => c.cveId), ids)
235235
})
236236

237+
test('CVE-ID on the summary line is kept as the summary', async () => {
238+
const commits = await toCommits([
239+
'commit 0000000000000000000000000000000000000000',
240+
'Author: RafaelGSS <rafael.nunu@hotmail.com>',
241+
'Date: Fri Nov 22 00:19:29 2024 -0300',
242+
'',
243+
' deps: CVE-ID: CVE-2024-1234 fix',
244+
'',
245+
' body line one'
246+
])
247+
assert.strictEqual(commits.length, 1)
248+
assert.strictEqual(commits[0].summary, 'deps: CVE-ID: CVE-2024-1234 fix')
249+
assert.deepStrictEqual(commits[0].description, ['body line one'])
250+
assert.strictEqual(commits[0].cveId, undefined)
251+
})
252+
253+
test('unindented CVE-ID line sets cveId', async () => {
254+
const commits = await toCommits([
255+
'commit 0000000000000000000000000000000000000000',
256+
'Author: RafaelGSS <rafael.nunu@hotmail.com>',
257+
'Date: Fri Nov 22 00:19:29 2024 -0300',
258+
'',
259+
' deps: fix vulnerability',
260+
'',
261+
'CVE-ID: CVE-2024-1234'
262+
])
263+
assert.strictEqual(commits.length, 1)
264+
assert.strictEqual(commits[0].cveId, 'CVE-2024-1234')
265+
})
266+
237267
test('body lines starting with "PR" are not PR urls', async () => {
238268
const commits = await toCommits([
239269
'commit 0000000000000000000000000000000000000000',

0 commit comments

Comments
 (0)