mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
hotfix: invalid OpenAPI spec versions causing the app to crash (#4559)
This commit is contained in:
parent
2b802ceb0d
commit
6c7628d15c
@ -1,12 +1,18 @@
|
||||
import { getVersionDisplayment } from '../workspace-card';
|
||||
|
||||
describe('getVersionDisplayment', () => {
|
||||
it('returns falsey values as-is', () => {
|
||||
expect(getVersionDisplayment(undefined)).toEqual(undefined);
|
||||
it('returns null, undefined, and empty string as-is', () => {
|
||||
expect(getVersionDisplayment(null)).toEqual(null);
|
||||
expect(getVersionDisplayment(undefined)).toEqual(undefined);
|
||||
expect(getVersionDisplayment('')).toEqual('');
|
||||
});
|
||||
|
||||
it('returns numbers as strings', () => {
|
||||
expect(getVersionDisplayment(0)).toEqual('v0'); // important to make sure we handle, since `0` is falsey
|
||||
expect(getVersionDisplayment(1)).toEqual('v1');
|
||||
expect(getVersionDisplayment(1.1)).toEqual('v1.1');
|
||||
});
|
||||
|
||||
it('does not add a `v` if the string starts with one', () => {
|
||||
expect(getVersionDisplayment('v1')).toEqual('v1');
|
||||
expect(getVersionDisplayment('victor')).toEqual('victor');
|
||||
|
@ -33,11 +33,20 @@ export interface WorkspaceCardProps {
|
||||
onSelect: (workspaceId: string, activity: GlobalActivity) => void;
|
||||
}
|
||||
|
||||
export const getVersionDisplayment = (version?: string | null) => {
|
||||
if (!version) {
|
||||
/** note: numbers are not technically valid (and, indeed, we throw a lint error), but we need to handle this case otherwise a user will not be able to import a spec with a malformed version and even _see_ that it's got the error. */
|
||||
export const getVersionDisplayment = (version?: string | number | null) => {
|
||||
if (version === null || version === undefined || version === '') {
|
||||
return version;
|
||||
}
|
||||
|
||||
if (typeof version === 'number') {
|
||||
console.warn(`OpenAPI documents must not use number data types for $.info.version, found ${version}`);
|
||||
version = String(version);
|
||||
} else if (typeof version !== 'string') {
|
||||
console.error('unable to parse spec version');
|
||||
return '';
|
||||
}
|
||||
|
||||
if (!version.startsWith('v')) {
|
||||
return `v${version}`;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user