Skip to content

Commit 2b64a2b

Browse files
authored
fix: add validation to mount-path (#2391)
* fix: add validation to mountPath
1 parent bc35914 commit 2b64a2b

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
lines changed

.changeset/violet-jobs-doubt.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@redocly/cli": patch
3+
---
4+
5+
Fixed an issue where the `mount-path` option was not validated, leading to errors when used with an empty path or a path identical to the project path.

docs/@v1/commands/push.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ REDOCLY_AUTHORIZATION=<api-key> redocly push <files> --organization <organizatio
3737
| files | [string] | **REQUIRED.** List of folders and/or files to upload. |
3838
| --organization, -o | string | **REQUIRED.** Organization slug. |
3939
| --project, -p | string | **REQUIRED.** Project slug. |
40-
| --mount-path, -mp | string | **REQUIRED.** The path where the files are mounted in the project. |
40+
| --mount-path, -mp | string | **REQUIRED.** The path where the files are mounted in the project. Cannot be empty or identical to the project path. |
4141
| --branch, -b | string | **REQUIRED.** The branch files are pushed from. |
4242
| --author, -a | string | **REQUIRED.** The author of the push in the format: `'Author Name <author-email@example.com>'`. |
4343
| --message, -m | string | **REQUIRED.** The commit message for the push. |

docs/@v2/commands/push.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ REDOCLY_AUTHORIZATION=<api-key> redocly push <files> --organization <organizatio
3333
| files | [string] | **REQUIRED.** List of folders and/or files to upload. |
3434
| --organization, -o | string | **REQUIRED.** Organization slug. |
3535
| --project, -p | string | **REQUIRED.** Project slug. |
36-
| --mount-path, -mp | string | **REQUIRED.** The path where the files are mounted in the project. |
36+
| --mount-path, -mp | string | **REQUIRED.** The path where the files are mounted in the project. Cannot be empty or identical to the project path. |
3737
| --branch, -b | string | **REQUIRED.** The branch files are pushed from. |
3838
| --author, -a | string | **REQUIRED.** The author of the push in the format: `'Author Name <author-email@example.com>'`. |
3939
| --message, -m | string | **REQUIRED.** The commit message for the push. |

packages/cli/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
import { handleRespect, type RespectArgv } from './commands/respect/index.js';
2929
import { version } from './utils/package.js';
3030
import { validatePositiveNumber } from './utils/validate-positive-number.js';
31+
import { validateMountPath } from './utils/validate-mount-path.js';
3132
import { validateMtlsCommandOption } from './commands/respect/mtls/validate-mtls-command-option.js';
3233

3334
import type { Arguments } from 'yargs';
@@ -247,6 +248,7 @@ yargs(hideBin(process.argv))
247248
type: 'string',
248249
alias: 'mp',
249250
required: true,
251+
coerce: validateMountPath,
250252
},
251253
author: {
252254
description: 'Author of the commit.',
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { describe, it, expect } from 'vitest';
2+
import { validateMountPath } from '../validate-mount-path.js';
3+
4+
describe('validateMountPath', () => {
5+
it('should accept valid mount path', () => {
6+
expect(validateMountPath('/docs')).toBe('/docs');
7+
expect(validateMountPath('/api/v1')).toBe('/api/v1');
8+
expect(validateMountPath('/my-path')).toBe('/my-path');
9+
});
10+
11+
it('should reject empty mount path', () => {
12+
expect(() => validateMountPath('')).toThrow(
13+
'Mount path cannot be empty or root path. Please use --mount-path option with a valid path.'
14+
);
15+
});
16+
17+
it('should reject root path "/"', () => {
18+
expect(() => validateMountPath('/')).toThrow(
19+
'Mount path cannot be empty or root path. Please use --mount-path option with a valid path.'
20+
);
21+
});
22+
});
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export function validateMountPath(value: string) {
2+
if (!value || value === '/') {
3+
throw new Error(
4+
'Mount path cannot be empty or root path. Please use --mount-path option with a valid path.'
5+
);
6+
}
7+
return value;
8+
}

0 commit comments

Comments
 (0)