fix backslash breaking path selection
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -20,14 +20,16 @@ export class PathType extends TypeValidation {
|
||||
public async to_type (value: unknown): Promise<unknown> {
|
||||
if (typeof value !== 'string')
|
||||
throw new Error (`invalid type for ${this.option_type}`);
|
||||
if (!await fs.pathExists (value))
|
||||
|
||||
const escaped = value.replace (/\\$/u, '');
|
||||
if (!await fs.pathExists (escaped))
|
||||
throw new Error ('path does not exist');
|
||||
if (this.option_type === 'path')
|
||||
return value;
|
||||
return escaped;
|
||||
|
||||
const stat = await fs.stat (value);
|
||||
const stat = await fs.stat (escaped);
|
||||
if (stat.isDirectory () === (this.option_type === 'folder'))
|
||||
return value;
|
||||
return escaped;
|
||||
|
||||
throw new Error ('cannot assign folder to file');
|
||||
}
|
||||
|
Reference in New Issue
Block a user