Browse Source

Fixes #2625 unescapes markdown for url

main
Eric Amodio 1 year ago
parent
commit
81c0a12e3a
4 changed files with 23 additions and 4 deletions
  1. +1
    -0
      CHANGELOG.md
  2. +4
    -2
      src/git/remotes/github.ts
  3. +4
    -2
      src/git/remotes/gitlab.ts
  4. +14
    -0
      src/system/string.ts

+ 1
- 0
CHANGELOG.md View File

@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/) and this p
### Fixed
- Fixes [#3018](https://github.com/gitkraken/vscode-gitlens/issues/3018) - Line blame overlay is broken when commit message contains a `)`
- Fixes [#2625](https://github.com/gitkraken/vscode-gitlens/issues/2625) - full issue ref has escape characters that break hover links
## [14.5.0] - 2023-11-13

+ 4
- 2
src/git/remotes/github.ts View File

@ -14,7 +14,7 @@ import { fromNow } from '../../system/date';
import { log } from '../../system/decorators/log';
import { memoize } from '../../system/decorators/memoize';
import { encodeUrl } from '../../system/encoding';
import { equalsIgnoreCase, escapeMarkdown } from '../../system/string';
import { equalsIgnoreCase, escapeMarkdown, unescapeMarkdown } from '../../system/string';
import { supportedInVSCodeVersion } from '../../system/utils';
import type { Account } from '../models/author';
import type { DefaultBranch } from '../models/defaultBranch';
@ -97,7 +97,9 @@ export class GitHubRemote extends RichRemoteProvider
return outputFormat === 'plaintext'
? text
: text.replace(autolinkFullIssuesRegex, (linkText: string, repo: string, num: string) => {
const url = encodeUrl(`${this.protocol}://${this.domain}/${repo}/issues/${num}`);
const url = encodeUrl(
`${this.protocol}://${this.domain}/${unescapeMarkdown(repo)}/issues/${num}`,
);
const title = ` "Open Issue or Pull Request #${num} from ${repo} on ${this.name}"`;
const token = `\x00${tokenMapping.size}\x00`;

+ 4
- 2
src/git/remotes/gitlab.ts View File

@ -13,7 +13,7 @@ import type { Brand, Unbrand } from '../../system/brand';
import { fromNow } from '../../system/date';
import { log } from '../../system/decorators/log';
import { encodeUrl } from '../../system/encoding';
import { equalsIgnoreCase, escapeMarkdown } from '../../system/string';
import { equalsIgnoreCase, escapeMarkdown, unescapeMarkdown } from '../../system/string';
import { supportedInVSCodeVersion } from '../../system/utils';
import type { Account } from '../models/author';
import type { DefaultBranch } from '../models/defaultBranch';
@ -96,7 +96,9 @@ export class GitLabRemote extends RichRemoteProvider
return outputFormat === 'plaintext'
? text
: text.replace(autolinkFullIssuesRegex, (linkText: string, repo: string, num: string) => {
const url = encodeUrl(`${this.protocol}://${this.domain}/${repo}/-/issues/${num}`);
const url = encodeUrl(
`${this.protocol}://${this.domain}/${unescapeMarkdown(repo)}/-/issues/${num}`,
);
const title = ` "Open Issue #${num} from ${repo} on ${this.name}"`;
const token = `\x00${tokenMapping.size}\x00`;

+ 14
- 0
src/system/string.ts View File

@ -126,7 +126,11 @@ export function encodeHtmlWeak(s: string | undefined): string | undefined {
}
const escapeMarkdownRegex = /[\\`*_{}[\]()#+\-.!]/g;
const unescapeMarkdownRegex = /\\([\\`*_{}[\]()#+\-.!])/g;
const escapeMarkdownHeaderRegex = /^===/gm;
const unescapeMarkdownHeaderRegex = /^\u200b===/gm;
// 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___';
const markdownQuotedRegex = /\r?\n/g;
@ -143,6 +147,16 @@ export function escapeMarkdown(s: string, options: { quoted?: boolean } = {}): s
return s.trim().replace(markdownQuotedRegex, '\t\\\n> ');
}
export function unescapeMarkdown(s: string): string {
return (
s
// Unescape markdown
.replace(unescapeMarkdownRegex, '$1')
// Unescape markdown header
.replace(unescapeMarkdownHeaderRegex, '===')
);
}
export function escapeRegex(s: string) {
return s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}

Loading…
Cancel
Save