Skip to content

Commit 6aab413

Browse files
committed
fix: refine trailer regex
Change-Id: Iab9d611eff4cfd4856190cf80fa916b080a61c15 Co-developed-by: Cursor <noreply@cursor.com>
1 parent 263ff03 commit 6aab413

2 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/commands/exec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,8 @@ function insertTrailers(
861861
let inTrailerSection = false;
862862

863863
// Regex patterns for trailer identification
864-
const trailerRegex = /^[a-zA-Z0-9-]{1,64}: /;
864+
// Require at least one '-' in the token to avoid "Solution: ..." being a trailer.
865+
const trailerRegex = /^[a-zA-Z0-9]+-[a-zA-Z0-9-]{0,63}: /;
865866
const trailerCommentRegex1 = /^\[.+\]$/;
866867
const trailerCommentRegex2 = /^\(.+\)$/;
867868

test/commands/exec.test.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,38 @@ describe('exec command utilities', () => {
435435
expect(lines[lines.length - 1]).toBe(`Change-Id: ${changeId}`);
436436
});
437437

438+
it('should not treat Solution: lines as trailers', () => {
439+
const message = 'feat: add new feature\n\nSolution: blah blah blah';
440+
const changeId = 'I123456789abcdef0123456789abcdef01234567';
441+
const result = insertTrailers(message, { ChangeId: changeId });
442+
const lines = result.split('\n');
443+
const solutionIndex = lines.findIndex(
444+
(line) => line === 'Solution: blah blah blah'
445+
);
446+
const changeIdIndex = lines.findIndex((line) =>
447+
line.startsWith('Change-Id:')
448+
);
449+
expect(solutionIndex).toBeGreaterThan(-1);
450+
expect(changeIdIndex).toBeGreaterThan(-1);
451+
expect(solutionIndex).toBeLessThan(changeIdIndex);
452+
expect(lines[changeIdIndex - 1]).toBe('');
453+
});
454+
455+
it('should not treat dash-leading tokens as trailers', () => {
456+
const message = 'feat: add new feature\n\n-Foo: bar';
457+
const changeId = 'I123456789abcdef0123456789abcdef01234567';
458+
const result = insertTrailers(message, { ChangeId: changeId });
459+
const lines = result.split('\n');
460+
const dashTokenIndex = lines.findIndex((line) => line === '-Foo: bar');
461+
const changeIdIndex = lines.findIndex((line) =>
462+
line.startsWith('Change-Id:')
463+
);
464+
expect(dashTokenIndex).toBeGreaterThan(-1);
465+
expect(changeIdIndex).toBeGreaterThan(-1);
466+
expect(dashTokenIndex).toBeLessThan(changeIdIndex);
467+
expect(lines[changeIdIndex - 1]).toBe('');
468+
});
469+
438470
it('should insert Change-Id before non-comment trailers', () => {
439471
const message =
440472
'feat: add new feature\n\nThis is a new feature\n\nSigned-off-by: user@example.com';

0 commit comments

Comments
 (0)