feat: tilde expansion for filename

This commit is contained in:
Lam Wei Li 2022-05-22 16:40:06 +08:00
parent e378b5bda4
commit a0eceefed1
No known key found for this signature in database
GPG Key ID: 90F6ABECF080D7BF
2 changed files with 8 additions and 0 deletions

View File

@ -31,6 +31,10 @@ function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset
throw new Error(`Invalid filename: ${file}`);
} else if (file.endsWith(path.sep)) {
throw new Error(`Filename is a directory: ${file}`);
} else {
// handle ~ expansion: https://github.com/nodejs/node/issues/684
// exclude ~ and ~filename as these can be valid files
file = file.replace(new RegExp(`^~(?=${path.sep}.+)`), os.homedir());
}
file = path.normalize(file);
numBackups = (!numBackups && numBackups !== 0) ? 5 : numBackups;

View File

@ -166,6 +166,10 @@ function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset
throw new Error(`Invalid filename: ${file}`);
} else if (file.endsWith(path.sep)) {
throw new Error(`Filename is a directory: ${file}`);
} else {
// handle ~ expansion: https://github.com/nodejs/node/issues/684
// exclude ~ and ~filename as these can be valid files
file = file.replace(new RegExp(`^~(?=${path.sep}.+)`), os.homedir());
}
file = path.normalize(file);
numBackups = (!numBackups && numBackups !== 0) ? 5 : numBackups;