mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 04:21:09 +00:00
fix: fix destination name validation (#1003)
This commit is contained in:
@@ -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', () => {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user