Skip to content

Commit 1eb9f49

Browse files
committed
Fixes #3018 escapes () in markdown command links
1 parent be50f2b commit 1eb9f49

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1414

1515
- Refines AI prompts to provide better commit message generation and explanation results
1616

17+
### Fixed
18+
19+
- Fixes [#3018](https://github.com/gitkraken/vscode-gitlens/issues/3018) - Line blame overlay is broken when commit message contains a `)`
20+
1721
## [14.5.0] - 2023-11-13
1822

1923
### Added

src/commands/base.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,8 @@ export abstract class Command implements Disposable {
285285
command: Commands | `${Commands.ActionPrefix}${ActionContext['type']}`,
286286
args: T,
287287
): string {
288-
return `command:${command}?${encodeURIComponent(JSON.stringify(args))}`;
288+
// Since we are using the command in a markdown link, we need to escape ()'s so they don't get interpreted as markdown
289+
return `command:${command}?${encodeURIComponent(JSON.stringify(args)).replace(/([()])/g, '\\$1')}`;
289290
}
290291

291292
protected readonly contextParsingOptions: CommandContextParsingOptions = { expectsEditor: false };

src/git/formatters/commitFormatter.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,8 @@ export class CommitFormatter extends Formatter<GitCommit, CommitFormatOptions> {
438438
if (arePlusFeaturesEnabled()) {
439439
commands += ` &nbsp;[$(gitlens-graph)](${Command.getMarkdownCommandArgsCore<ShowInCommitGraphCommandArgs>(
440440
Commands.ShowInCommitGraph,
441-
{ ref: getReferenceFromRevision(this._item) },
441+
// Avoid including the message here, it just bloats the command url
442+
{ ref: getReferenceFromRevision(this._item, { excludeMessage: true }) },
442443
)} "Open in Commit Graph")`;
443444
}
444445

src/git/models/reference.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,20 +233,20 @@ export function getReferenceFromBranch(branch: GitBranchReference) {
233233
});
234234
}
235235

236-
export function getReferenceFromRevision(revision: GitRevisionReference) {
236+
export function getReferenceFromRevision(revision: GitRevisionReference, options?: { excludeMessage?: boolean }) {
237237
if (revision.refType === 'stash') {
238238
return createReference(revision.ref, revision.repoPath, {
239239
refType: revision.refType,
240240
name: revision.name,
241241
number: revision.number,
242-
message: revision.message,
242+
message: options?.excludeMessage ? undefined : revision.message,
243243
});
244244
}
245245

246246
return createReference(revision.ref, revision.repoPath, {
247247
refType: revision.refType,
248248
name: revision.name,
249-
message: revision.message,
249+
message: options?.excludeMessage ? undefined : revision.message,
250250
});
251251
}
252252

0 commit comments

Comments
 (0)