Browse Source

Fixes more remote url encoding issues

main
Eric Amodio 4 years ago
parent
commit
5f95876a97
7 changed files with 80 additions and 70 deletions
  1. +7
    -7
      src/git/remotes/azure-devops.ts
  2. +7
    -7
      src/git/remotes/bitbucket-server.ts
  3. +7
    -7
      src/git/remotes/bitbucket.ts
  4. +24
    -15
      src/git/remotes/custom.ts
  5. +7
    -7
      src/git/remotes/github.ts
  6. +7
    -7
      src/git/remotes/gitlab.ts
  7. +21
    -20
      src/git/remotes/provider.ts

+ 7
- 7
src/git/remotes/azure-devops.ts View File

@ -113,19 +113,19 @@ export class AzureDevOpsRemote extends RemoteProvider {
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
return this.encodeUrl(`${this.baseUrl}/branches`);
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/?version=GB${branch}&_a=history`;
return this.encodeUrl(`${this.baseUrl}/?version=GB${branch}&_a=history`);
}
protected getUrlForCommit(sha: string): string {
return `${this.baseUrl}/commit/${sha}`;
return this.encodeUrl(`${this.baseUrl}/commit/${sha}`);
}
protected getUrlForComparison(base: string, compare: string, _notation: '..' | '...'): string {
return `${this.baseUrl}/branchCompare?baseVersion=GB${base}&targetVersion=GB${compare}`;
return this.encodeUrl(`${this.baseUrl}/branchCompare?baseVersion=GB${base}&targetVersion=GB${compare}`);
}
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
@ -140,8 +140,8 @@ export class AzureDevOpsRemote extends RemoteProvider {
line = '';
}
if (sha) return `${this.baseUrl}/commit/${sha}/?_a=contents&path=/${fileName}${line}`;
if (branch) return `${this.baseUrl}/?path=/${fileName}&version=GB${branch}&_a=contents${line}`;
return `${this.baseUrl}?path=/${fileName}${line}`;
if (sha) return this.encodeUrl(`${this.baseUrl}/commit/${sha}/?_a=contents&path=/${fileName}${line}`);
if (branch) return this.encodeUrl(`${this.baseUrl}/?path=/${fileName}&version=GB${branch}&_a=contents${line}`);
return this.encodeUrl(`${this.baseUrl}?path=/${fileName}${line}`);
}
}

+ 7
- 7
src/git/remotes/bitbucket-server.ts View File

@ -115,19 +115,19 @@ export class BitbucketServerRemote extends RemoteProvider {
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
return this.encodeUrl(`${this.baseUrl}/branches`);
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/commits?until=${branch}`;
return this.encodeUrl(`${this.baseUrl}/commits?until=${branch}`);
}
protected getUrlForCommit(sha: string): string {
return `${this.baseUrl}/commits/${sha}`;
return this.encodeUrl(`${this.baseUrl}/commits/${sha}`);
}
protected getUrlForComparison(base: string, compare: string, _notation: '..' | '...'): string {
return `${this.baseUrl}/branches/compare/${base}%0D${compare}`;
return this.encodeUrl(`${this.baseUrl}/branches/compare/${base}%0D${compare}`).replace('%250D', '%0D');
}
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
@ -141,8 +141,8 @@ export class BitbucketServerRemote extends RemoteProvider {
} else {
line = '';
}
if (sha) return `${this.baseUrl}/browse/${fileName}?at=${sha}${line}`;
if (branch) return `${this.baseUrl}/browse/${fileName}?at=${branch}${line}`;
return `${this.baseUrl}/browse/${fileName}${line}`;
if (sha) return `${this.encodeUrl(`${this.baseUrl}/browse/${fileName}?at=${sha}`)}${line}`;
if (branch) return `${this.encodeUrl(`${this.baseUrl}/browse/${fileName}?at=${branch}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}/browse/${fileName}`)}${line}`;
}
}

+ 7
- 7
src/git/remotes/bitbucket.ts View File

@ -108,19 +108,19 @@ export class BitbucketRemote extends RemoteProvider {
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
return this.encodeUrl(`${this.baseUrl}/branches`);
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/branch/${branch}`;
return this.encodeUrl(`${this.baseUrl}/branch/${branch}`);
}
protected getUrlForCommit(sha: string): string {
return `${this.baseUrl}/commits/${sha}`;
return this.encodeUrl(`${this.baseUrl}/commits/${sha}`);
}
protected getUrlForComparison(base: string, compare: string, _notation: '..' | '...'): string {
return `${this.baseUrl}/branches/compare/${base}%0D${compare}`;
return this.encodeUrl(`${this.baseUrl}/branches/compare/${base}%0D${compare}`).replace('%250D', '%0D');
}
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
@ -135,8 +135,8 @@ export class BitbucketRemote extends RemoteProvider {
line = '';
}
if (sha) return `${this.baseUrl}/src/${sha}/${fileName}${line}`;
if (branch) return `${this.baseUrl}/src/${branch}/${fileName}${line}`;
return `${this.baseUrl}?path=${fileName}${line}`;
if (sha) return `${this.encodeUrl(`${this.baseUrl}/src/${sha}/${fileName}`)}${line}`;
if (branch) return `${this.encodeUrl(`${this.baseUrl}/src/${branch}/${fileName}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}?path=${fileName}`)}${line}`;
}
}

+ 24
- 15
src/git/remotes/custom.ts View File

@ -29,27 +29,29 @@ export class CustomRemote extends RemoteProvider {
}
protected getUrlForRepository(): string {
return Strings.interpolate(this.urls.repository, this.getContext());
return this.encodeUrl(Strings.interpolate(this.urls.repository, this.getContext()));
}
protected getUrlForBranches(): string {
return Strings.interpolate(this.urls.branches, this.getContext());
return this.encodeUrl(Strings.interpolate(this.urls.branches, this.getContext()));
}
protected getUrlForBranch(branch: string): string {
return Strings.interpolate(this.urls.branch, this.getContext({ branch: branch }));
return this.encodeUrl(Strings.interpolate(this.urls.branch, this.getContext({ branch: branch })));
}
protected getUrlForCommit(sha: string): string {
return Strings.interpolate(this.urls.commit, this.getContext({ id: sha }));
return this.encodeUrl(Strings.interpolate(this.urls.commit, this.getContext({ id: sha })));
}
protected getUrlForComparison(base: string, compare: string, notation: '..' | '...'): string | undefined {
if (this.urls.comparison == null) return undefined;
return Strings.interpolate(
this.urls.comparison,
this.getContext({ ref1: base, ref2: compare, notation: notation }),
return this.encodeUrl(
Strings.interpolate(
this.urls.comparison,
this.getContext({ ref1: base, ref2: compare, notation: notation }),
),
);
}
@ -65,19 +67,26 @@ export class CustomRemote extends RemoteProvider {
line = '';
}
let url;
if (sha) {
return Strings.interpolate(
this.urls.fileInCommit,
this.getContext({ id: sha, file: fileName, line: line }),
);
}
if (branch) {
return Strings.interpolate(
url = Strings.interpolate(this.urls.fileInCommit, this.getContext({ id: sha, file: fileName, line: line }));
} else if (branch) {
url = Strings.interpolate(
this.urls.fileInBranch,
this.getContext({ branch: branch, file: fileName, line: line }),
);
} else {
url = Strings.interpolate(this.urls.file, this.getContext({ file: fileName, line: line }));
}
url = this.encodeUrl(url);
if (line.includes('#')) {
const index = url.lastIndexOf('%23');
if (index !== -1) {
url = `${url.substring(0, index)}#${url.substring(index + 3)}`;
}
}
return Strings.interpolate(this.urls.file, this.getContext({ file: fileName, line: line }));
return url;
}
private getContext(context?: Record<string, unknown>) {

+ 7
- 7
src/git/remotes/github.ts View File

@ -128,19 +128,19 @@ export class GitHubRemote extends RichRemoteProvider {
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
return this.encodeUrl(`${this.baseUrl}/branches`);
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/tree/${branch}`;
return this.encodeUrl(`${this.baseUrl}/tree/${branch}`);
}
protected getUrlForCommit(sha: string): string {
return `${this.baseUrl}/commit/${sha}`;
return this.encodeUrl(`${this.baseUrl}/commit/${sha}`);
}
protected getUrlForComparison(base: string, compare: string, notation: '..' | '...'): string {
return `${this.baseUrl}/compare/${base}${notation}${compare}`;
return this.encodeUrl(`${this.baseUrl}/compare/${base}${notation}${compare}`);
}
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
@ -155,9 +155,9 @@ export class GitHubRemote extends RichRemoteProvider {
line = '';
}
if (sha) return `${this.baseUrl}/blob/${sha}/${fileName}${line}`;
if (branch) return `${this.baseUrl}/blob/${branch}/${fileName}${line}`;
return `${this.baseUrl}?path=${fileName}${line}`;
if (sha) return `${this.encodeUrl(`${this.baseUrl}/blob/${sha}/${fileName}`)}${line}`;
if (branch) return `${this.encodeUrl(`${this.baseUrl}/blob/${branch}/${fileName}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}?path=${fileName}`)}${line}`;
}
protected async getProviderAccountForCommit(

+ 7
- 7
src/git/remotes/gitlab.ts View File

@ -103,19 +103,19 @@ export class GitLabRemote extends RemoteProvider {
}
protected getUrlForBranches(): string {
return `${this.baseUrl}/branches`;
return this.encodeUrl(`${this.baseUrl}/branches`);
}
protected getUrlForBranch(branch: string): string {
return `${this.baseUrl}/tree/${branch}`;
return this.encodeUrl(`${this.baseUrl}/tree/${branch}`);
}
protected getUrlForCommit(sha: string): string {
return `${this.baseUrl}/commit/${sha}`;
return this.encodeUrl(`${this.baseUrl}/commit/${sha}`);
}
protected getUrlForComparison(base: string, compare: string, notation: '..' | '...'): string {
return `${this.baseUrl}/-/compare/${base}${notation}${compare}`;
return this.encodeUrl(`${this.baseUrl}/-/compare/${base}${notation}${compare}`);
}
protected getUrlForFile(fileName: string, branch?: string, sha?: string, range?: Range): string {
@ -130,8 +130,8 @@ export class GitLabRemote extends RemoteProvider {
line = '';
}
if (sha) return `${this.baseUrl}/blob/${sha}/${fileName}${line}`;
if (branch) return `${this.baseUrl}/blob/${branch}/${fileName}${line}`;
return `${this.baseUrl}?path=${fileName}${line}`;
if (sha) return `${this.encodeUrl(`${this.baseUrl}/blob/${sha}/${fileName}`)}${line}`;
if (branch) return `${this.encodeUrl(`${this.baseUrl}/blob/${branch}/${fileName}`)}${line}`;
return `${this.encodeUrl(`${this.baseUrl}?path=${fileName}`)}${line}`;
}
}

+ 21
- 20
src/git/remotes/provider.ts View File

@ -145,34 +145,29 @@ export abstract class RemoteProvider implements RemoteProviderReference {
url(resource: RemoteResource): string | undefined {
switch (resource.type) {
case RemoteResourceType.Branch:
return encodeURI(this.getUrlForBranch(resource.branch));
return this.getUrlForBranch(resource.branch);
case RemoteResourceType.Branches:
return encodeURI(this.getUrlForBranches());
return this.getUrlForBranches();
case RemoteResourceType.Commit:
return encodeURI(this.getUrlForCommit(resource.sha));
return this.getUrlForCommit(resource.sha);
case RemoteResourceType.Comparison: {
const url = this.getUrlForComparison?.(resource.base, resource.compare, resource.notation ?? '...');
return url != null ? encodeURI(url) : undefined;
return this.getUrlForComparison?.(resource.base, resource.compare, resource.notation ?? '...');
}
case RemoteResourceType.File:
return encodeURI(
this.getUrlForFile(
resource.fileName,
resource.branchOrTag != null ? resource.branchOrTag : undefined,
undefined,
resource.range,
),
return this.getUrlForFile(
resource.fileName,
resource.branchOrTag != null ? resource.branchOrTag : undefined,
undefined,
resource.range,
);
case RemoteResourceType.Repo:
return encodeURI(this.getUrlForRepository());
return this.getUrlForRepository();
case RemoteResourceType.Revision:
return encodeURI(
this.getUrlForFile(
resource.fileName,
resource.branchOrTag != null ? resource.branchOrTag : undefined,
resource.sha != null ? resource.sha : undefined,
resource.range,
),
return this.getUrlForFile(
resource.fileName,
resource.branchOrTag != null ? resource.branchOrTag : undefined,
resource.sha != null ? resource.sha : undefined,
resource.range,
);
default:
return undefined;
@ -212,6 +207,12 @@ export abstract class RemoteProvider implements RemoteProviderReference {
return env.openExternal(Uri.parse(url));
}
protected encodeUrl(url: string): string;
protected encodeUrl(url: string | undefined): string | undefined;
protected encodeUrl(url: string | undefined): string | undefined {
return url != null ? encodeURI(url).replace(/#/g, '%23') : undefined;
}
}
const _onDidChangeAuthentication = new EventEmitter<{ reason: 'connected' | 'disconnected'; key: string }>();

Loading…
Cancel
Save