Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sfppackage): fix handling of URL-encoded spaces in repository URLs #138

Merged
Merged
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
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 @@
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);

Check failure on line 93 in src/core/package/SfpPackageInquirer.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/package/SfpPackageInquirer.ts#L93

Unsafe assignment of an error typed value.

Check failure on line 93 in src/core/package/SfpPackageInquirer.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

src/core/package/SfpPackageInquirer.ts#L93

Unsafe call of an `error` type typed value.
} 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 = '[email protected]: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 = '[email protected]: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");
});
});
});