Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "",
"type": "none",
"packageName": "@microsoft/rush"
}
],
"packageName": "@microsoft/rush",
"email": "iclanton@users.noreply.github.com"
}
45 changes: 25 additions & 20 deletions libraries/rush-lib/src/logic/Git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import type child_process from 'node:child_process';
import * as path from 'node:path';
import * as url from 'node:url';

import gitInfo from 'git-repo-info';
import { trueCasePathSync } from 'true-case-path';
Expand Down Expand Up @@ -487,25 +486,31 @@ export class Git {
}
}

const parsedUrl: url.UrlWithStringQuery = url.parse(result);

// Only convert recognized schemes

switch (parsedUrl.protocol) {
case 'http:':
case 'https:':
case 'ssh:':
case 'ftp:':
case 'ftps:':
case 'git:':
case 'git+http:':
case 'git+https:':
case 'git+ssh:':
case 'git+ftp:':
case 'git+ftps:':
// Assemble the parts we want:
result = `https://${parsedUrl.host}${parsedUrl.pathname}`;
break;
// Use the WHATWG URL API instead of the deprecated url.parse().
// The URL constructor throws for non-standard URLs (e.g. local paths), so we
// catch and leave the result unchanged in that case.
try {
const parsedUrl: URL = new URL(result);

// Only convert recognized schemes
switch (parsedUrl.protocol) {
case 'http:':
case 'https:':
case 'ssh:':
case 'ftp:':
case 'ftps:':
case 'git:':
case 'git+http:':
case 'git+https:':
case 'git+ssh:':
case 'git+ftp:':
case 'git+ftps:':
// Assemble the parts we want:
result = `https://${parsedUrl.host}${parsedUrl.pathname}`;
break;
}
} catch {
// Not a valid URL (e.g. a local path) -- leave result unchanged
}

// Trim ".git" or ".git/" from the end
Expand Down
2 changes: 1 addition & 1 deletion libraries/rush-lib/src/logic/test/Git.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe(Git.name, () => {
'https://host.xz/path/to/repo'
);
expect(Git.normalizeGitUrlForComparison('http://host.xz:80/path/to/repo')).toEqual(
'https://host.xz:80/path/to/repo'
'https://host.xz/path/to/repo'
);
expect(Git.normalizeGitUrlForComparison('host.xz:path/to/repo.git/')).toEqual(
'https://host.xz/path/to/repo'
Expand Down