Skip to content

Commit

Permalink
fix(git-url): clean up state of parsed URL (#24306)
Browse files Browse the repository at this point in the history
Signed-off-by: Luís Cobucci <lcobucci@gmail.com>
Co-authored-by: Tobias <github@tobiasgabriel.de>
  • Loading branch information
lcobucci and Shegox committed Sep 14, 2023
1 parent 69e7c80 commit 0b50feb
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/modules/manager/git-submodules/extract.spec.ts
Expand Up @@ -247,7 +247,7 @@ describe('modules/manager/git-submodules/extract', () => {
currentValue: 'main',
depName: 'some-azure',
packageName:
'https://organization@dev.azure.com/organization/whitespace%20project/_git/repo',
'https://dev.azure.com/organization/whitespace%20project/_git/repo',
},
],
});
Expand Down
15 changes: 15 additions & 0 deletions lib/util/git/url.spec.ts
Expand Up @@ -78,6 +78,21 @@ describe('util/git/url', () => {
'https://x-access-token:token@github.com/some/repo'
);
});

it('removes username/password from URL', () => {
expect(getHttpUrl('https://user:password@foo.bar/someOrg/someRepo')).toBe(
'https://foo.bar/someOrg/someRepo'
);
});

it('replaces username/password with given token', () => {
expect(
getHttpUrl(
'https://user:password@foo.bar/someOrg/someRepo',
'another-user:a-secret-pwd'
)
).toBe('https://another-user:a-secret-pwd@foo.bar/someOrg/someRepo');
});
});

describe('getRemoteUrlWithToken()', () => {
Expand Down
1 change: 1 addition & 0 deletions lib/util/git/url.ts
Expand Up @@ -15,6 +15,7 @@ export function getHttpUrl(url: string, token?: string): string {
? parsedUrl.protocol
: 'https';

parsedUrl.user = '';
parsedUrl.token = token ?? '';

if (token) {
Expand Down

0 comments on commit 0b50feb

Please sign in to comment.