Browse Source

Fixes #1695: properly encodes hover links

main
Eric Amodio 3 years ago
parent
commit
967dcb6cf4
4 changed files with 17 additions and 9 deletions
  1. +3
    -3
      src/annotations/autolinks.ts
  2. +2
    -6
      src/git/remotes/provider.ts
  3. +1
    -0
      src/system.ts
  4. +11
    -0
      src/system/encoding.ts

+ 3
- 3
src/annotations/autolinks.ts View File

@ -5,7 +5,7 @@ import { GlyphChars } from '../constants';
import { Container } from '../container';
import { GitRemote, IssueOrPullRequest } from '../git/git';
import { Logger } from '../logger';
import { Dates, debug, Iterables, Promises, Strings } from '../system';
import { Dates, debug, Encoding, Iterables, Promises, Strings } from '../system';
const numRegex = /<num>/g;
@ -157,7 +157,7 @@ export class Autolinks implements Disposable {
}
if (issuesOrPullRequests == null || issuesOrPullRequests.size === 0) {
const replacement = `[$1](${ref.url.replace(numRegex, '$2')}${
const replacement = `[$1](${Encoding.encodeUrl(ref.url.replace(numRegex, '$2'))}${
ref.title ? ` "${ref.title.replace(numRegex, '$2')}"` : ''
})`;
ref.linkify = (text: string, markdown: boolean) =>
@ -174,7 +174,7 @@ export class Autolinks implements Disposable {
return text.replace(ref.messageMarkdownRegex!, (_substring, linkText, num) => {
const issue = issuesOrPullRequests?.get(num);
const issueUrl = ref.url.replace(numRegex, num);
const issueUrl = Encoding.encodeUrl(ref.url.replace(numRegex, num));
let title = '';
if (ref.title) {

+ 2
- 6
src/git/remotes/provider.ts View File

@ -14,7 +14,7 @@ import { AutolinkReference } from '../../config';
import { WorkspaceState } from '../../constants';
import { Container } from '../../container';
import { Logger } from '../../logger';
import { debug, gate, log, Promises } from '../../system';
import { debug, Encoding, gate, log, Promises } from '../../system';
import {
Account,
DefaultBranch,
@ -234,11 +234,7 @@ export abstract class RemoteProvider implements RemoteProviderReference {
protected encodeUrl(url: string): string;
protected encodeUrl(url: string | undefined): string | undefined;
protected encodeUrl(url: string | undefined): string | undefined {
if (url == null) return undefined;
// Not a fan of this, but it's hard to gauge previous encoding and this is the most common case
url = url.replace(/%20/g, ' ');
return encodeURI(url).replace(/#/g, '%23');
return Encoding.encodeUrl(url);
}
}

+ 1
- 0
src/system.ts View File

@ -24,6 +24,7 @@ export * from './system/decorators/gate';
export * from './system/decorators/log';
export * from './system/decorators/memoize';
export * from './system/decorators/timeout';
export * as Encoding from './system/encoding';
export * as Functions from './system/function';
export * as Iterables from './system/iterable';
export * as Objects from './system/object';

+ 11
- 0
src/system/encoding.ts View File

@ -0,0 +1,11 @@
'use strict';
export function encodeUrl(url: string): string;
export function encodeUrl(url: string | undefined): string | undefined;
export function encodeUrl(url: string | undefined): string | undefined {
if (url == null) return undefined;
// Not a fan of this, but it's hard to gauge previous encoding and this is the most common case
url = url.replace(/%20/g, ' ');
return encodeURI(url).replace(/#/g, '%23');
}

Loading…
Cancel
Save