Skip to content

Commit 81c0a12

Browse files
committed
Fixes #2625 unescapes markdown for url
1 parent 021dbdc commit 81c0a12

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
1818
### Fixed
1919

2020
- Fixes [#3018](https://github.com/gitkraken/vscode-gitlens/issues/3018) - Line blame overlay is broken when commit message contains a `)`
21+
- Fixes [#2625](https://github.com/gitkraken/vscode-gitlens/issues/2625) - full issue ref has escape characters that break hover links
2122

2223
## [14.5.0] - 2023-11-13
2324

src/git/remotes/github.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { fromNow } from '../../system/date';
1414
import { log } from '../../system/decorators/log';
1515
import { memoize } from '../../system/decorators/memoize';
1616
import { encodeUrl } from '../../system/encoding';
17-
import { equalsIgnoreCase, escapeMarkdown } from '../../system/string';
17+
import { equalsIgnoreCase, escapeMarkdown, unescapeMarkdown } from '../../system/string';
1818
import { supportedInVSCodeVersion } from '../../system/utils';
1919
import type { Account } from '../models/author';
2020
import type { DefaultBranch } from '../models/defaultBranch';
@@ -97,7 +97,9 @@ export class GitHubRemote extends RichRemoteProvider<GitHubRepositoryDescriptor>
9797
return outputFormat === 'plaintext'
9898
? text
9999
: text.replace(autolinkFullIssuesRegex, (linkText: string, repo: string, num: string) => {
100-
const url = encodeUrl(`${this.protocol}://${this.domain}/${repo}/issues/${num}`);
100+
const url = encodeUrl(
101+
`${this.protocol}://${this.domain}/${unescapeMarkdown(repo)}/issues/${num}`,
102+
);
101103
const title = ` "Open Issue or Pull Request #${num} from ${repo} on ${this.name}"`;
102104

103105
const token = `\x00${tokenMapping.size}\x00`;

src/git/remotes/gitlab.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import type { Brand, Unbrand } from '../../system/brand';
1313
import { fromNow } from '../../system/date';
1414
import { log } from '../../system/decorators/log';
1515
import { encodeUrl } from '../../system/encoding';
16-
import { equalsIgnoreCase, escapeMarkdown } from '../../system/string';
16+
import { equalsIgnoreCase, escapeMarkdown, unescapeMarkdown } from '../../system/string';
1717
import { supportedInVSCodeVersion } from '../../system/utils';
1818
import type { Account } from '../models/author';
1919
import type { DefaultBranch } from '../models/defaultBranch';
@@ -96,7 +96,9 @@ export class GitLabRemote extends RichRemoteProvider<GitLabRepositoryDescriptor>
9696
return outputFormat === 'plaintext'
9797
? text
9898
: text.replace(autolinkFullIssuesRegex, (linkText: string, repo: string, num: string) => {
99-
const url = encodeUrl(`${this.protocol}://${this.domain}/${repo}/-/issues/${num}`);
99+
const url = encodeUrl(
100+
`${this.protocol}://${this.domain}/${unescapeMarkdown(repo)}/-/issues/${num}`,
101+
);
100102
const title = ` "Open Issue #${num} from ${repo} on ${this.name}"`;
101103

102104
const token = `\x00${tokenMapping.size}\x00`;

src/system/string.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,11 @@ export function encodeHtmlWeak(s: string | undefined): string | undefined {
126126
}
127127

128128
const escapeMarkdownRegex = /[\\`*_{}[\]()#+\-.!]/g;
129+
const unescapeMarkdownRegex = /\\([\\`*_{}[\]()#+\-.!])/g;
130+
129131
const escapeMarkdownHeaderRegex = /^===/gm;
132+
const unescapeMarkdownHeaderRegex = /^\u200b===/gm;
133+
130134
// const sampleMarkdown = '## message `not code` *not important* _no underline_ \n> don\'t quote me \n- don\'t list me \n+ don\'t list me \n1. don\'t list me \nnot h1 \n=== \nnot h2 \n---\n***\n---\n___';
131135
const markdownQuotedRegex = /\r?\n/g;
132136

@@ -143,6 +147,16 @@ export function escapeMarkdown(s: string, options: { quoted?: boolean } = {}): s
143147
return s.trim().replace(markdownQuotedRegex, '\t\\\n> ');
144148
}
145149

150+
export function unescapeMarkdown(s: string): string {
151+
return (
152+
s
153+
// Unescape markdown
154+
.replace(unescapeMarkdownRegex, '$1')
155+
// Unescape markdown header
156+
.replace(unescapeMarkdownHeaderRegex, '===')
157+
);
158+
}
159+
146160
export function escapeRegex(s: string) {
147161
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
148162
}

0 commit comments

Comments
 (0)