Skip to content

Commit

Permalink
fix(sfppackage): fix handling of URL-encoded spaces in repository URLs (
Browse files Browse the repository at this point in the history
#138)

* fix(sfppackage): improve error message when repository URL is not parseable

This adds a skipped test that should be enabled after #137

* fix(sfppackage): fix handling of URL-encoded whitespace in repository URL

This updates git-parse-url to version 16.0.0.
  • Loading branch information
richard-giraud authored Nov 27, 2024
1 parent 357b118 commit c50cd25
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 14 deletions.
31 changes: 19 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"dotenv": "16.3.1",
"fast-xml-parser": "4.5.0",
"fs-extra": "^11.1.1",
"git-url-parse": "14.0.0",
"git-url-parse": "^16.0.0",
"glob": "^10.3.3",
"handlebars": "^4.7.7",
"hot-shots": "^8.5.0",
Expand Down
14 changes: 13 additions & 1 deletion src/core/package/SfpPackageInquirer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,19 @@ export default class SfpPackageInquirer {
let remoteURL: gitUrlParse.GitUrl;

for (let sfpPackage of this.sfpPackages) {
let currentRemoteURL = gitUrlParse(sfpPackage.repository_url);
let currentRemoteURL: gitUrlParse.GitUrl;

try {
currentRemoteURL = gitUrlParse(sfpPackage.repository_url);
} catch (ex) {
if (ex instanceof Error && ex.message === 'URL parsing failed.') {
throw new Error(
`Invalid repository URL for package '${sfpPackage.package_name}': ${sfpPackage.repository_url}`
);
} else {
throw ex;
}
}

if (remoteURL == null) {
remoteURL = currentRemoteURL;
Expand Down
45 changes: 45 additions & 0 deletions tests/core/package/SfpPackageInquirer.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import { expect } from '@jest/globals';
import SfpPackage from '../../../lib/core/package/SfpPackage';
import SfpPackageInquirer from '../../../src/core/package/SfpPackageInquirer';

describe('validateArtifactsSourceRepository', () => {
describe('Given a bad repository URL, display', () => {
it('should accept a good repository SSH URL', async () => {
const repositoryUrl = 'git@github.com:flxbl-io/sfp-test.git';

let sfpPackage: SfpPackage = new SfpPackage();
sfpPackage.package_name = 'testPackageName';
sfpPackage.repository_url = repositoryUrl;

let sfpPackageInquirer = new SfpPackageInquirer([sfpPackage]);
sfpPackageInquirer.validateArtifactsSourceRepository();
});

it('should accept a good repository SSH URL with a URL-encoded space', async () => {
const repositoryUrl = 'git@github.com:flxbl-io/sfp%20test.git';

let sfpPackage: SfpPackage = new SfpPackage();
sfpPackage.package_name = 'testPackageName';
sfpPackage.repository_url = repositoryUrl;

let sfpPackageInquirer = new SfpPackageInquirer([sfpPackage]);
sfpPackageInquirer.validateArtifactsSourceRepository();
});

it('should reject a bad repository SSH URL with a helpful error message', async () => {
const repositoryUrl = 'git';

const t = () => {
let sfpPackage: SfpPackage = new SfpPackage();
sfpPackage.package_name = 'testPackageName';
sfpPackage.repository_url = repositoryUrl;

let sfpPackageInquirer = new SfpPackageInquirer([sfpPackage]);
sfpPackageInquirer.validateArtifactsSourceRepository();
};

expect(t).toThrow(Error);
expect(t).toThrow("Invalid repository URL for package 'testPackageName': git");
});
});
});

0 comments on commit c50cd25

Please sign in to comment.