fix: fix destination name validation (#1003)

This commit is contained in:
Ihor Karpiuk
2023-01-26 12:37:14 +02:00
committed by GitHub
parent fac9b65113
commit 194b91458e
2 changed files with 32 additions and 1 deletions

View File

@@ -202,6 +202,37 @@ describe('getDestinationProps', () => {
version: 'v1',
});
});
it('should return organizationId from destination string', () => {
expect(getDestinationProps('@test-org/main@main-v1', undefined)).toEqual({
organizationId: 'test-org',
name: 'main',
version: 'main-v1',
});
});
it('should return organizationId, version and empty name from destination string', () => {
expect(getDestinationProps('@test_org/@main_v1', undefined)).toEqual({
organizationId: 'test_org',
name: '',
version: 'main_v1',
});
});
it('should validate organizationId with space and version with dot', () => {
expect(getDestinationProps('@test org/simple_name@main.v1', undefined)).toEqual({
organizationId: 'test org',
name: 'simple_name',
version: 'main.v1',
});
});
it('should not work with "@" in destination name', () => {
expect(getDestinationProps('@test org/simple@name@main.v1', undefined)).toEqual({
organizationId: undefined,
name: undefined,
version: undefined,
});
});
});
describe('getApiRoot', () => {

View File

@@ -302,7 +302,7 @@ function hashFiles(filePaths: { filePath: string }[]) {
}
function validateDestination(destination: string) {
const regexp = /^(@(?<organizationId>\w+)\/)?(?<name>.*)@(?<version>[\w\.\-\_]+)$/;
const regexp = /^(@(?<organizationId>[\w\-\s]+)\/)?(?<name>[^@]*)@(?<version>[\w\.\-]+)$/;
return destination?.match(regexp)?.groups;
}