mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
fix: filename validation (cannot be directory)
This commit is contained in:
parent
6de1da298e
commit
d182204079
@ -29,6 +29,8 @@ function mainSighupHandler() {
|
||||
function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset) {
|
||||
if (typeof file !== "string" || file.length === 0) {
|
||||
throw new Error(`Invalid filename: ${file}`);
|
||||
} else if (file.endsWith(path.sep)) {
|
||||
throw new Error(`Filename is a directory: ${file}`);
|
||||
}
|
||||
file = path.normalize(file);
|
||||
numBackups = (!numBackups && numBackups !== 0) ? 5 : numBackups;
|
||||
|
||||
@ -164,6 +164,8 @@ class RollingFileSync {
|
||||
function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset) {
|
||||
if (typeof file !== "string" || file.length === 0) {
|
||||
throw new Error(`Invalid filename: ${file}`);
|
||||
} else if (file.endsWith(path.sep)) {
|
||||
throw new Error(`Filename is a directory: ${file}`);
|
||||
}
|
||||
file = path.normalize(file);
|
||||
numBackups = (!numBackups && numBackups !== 0) ? 5 : numBackups;
|
||||
|
||||
@ -50,7 +50,6 @@ test("log4js fileAppender", batch => {
|
||||
|
||||
batch.test("should give error if invalid filename", async t => {
|
||||
const file = "";
|
||||
const expectedError = new Error(`Invalid filename: ${file}`);
|
||||
t.throws(
|
||||
() =>
|
||||
log4js.configure({
|
||||
@ -64,7 +63,23 @@ test("log4js fileAppender", batch => {
|
||||
default: { appenders: ["file"], level: "debug" }
|
||||
}
|
||||
}),
|
||||
expectedError
|
||||
new Error(`Invalid filename: ${file}`)
|
||||
);
|
||||
const dir = `.${path.sep}`;
|
||||
t.throws(
|
||||
() =>
|
||||
log4js.configure({
|
||||
appenders: {
|
||||
file: {
|
||||
type: "file",
|
||||
filename: dir
|
||||
}
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ["file"], level: "debug" }
|
||||
}
|
||||
}),
|
||||
new Error(`Filename is a directory: ${dir}`)
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
@ -78,7 +78,6 @@ test("log4js fileSyncAppender", batch => {
|
||||
|
||||
batch.test("should give error if invalid filename", async t => {
|
||||
const file = "";
|
||||
const expectedError = new Error(`Invalid filename: ${file}`);
|
||||
t.throws(
|
||||
() =>
|
||||
log4js.configure({
|
||||
@ -92,7 +91,23 @@ test("log4js fileSyncAppender", batch => {
|
||||
default: { appenders: ["file"], level: "debug" }
|
||||
}
|
||||
}),
|
||||
expectedError
|
||||
new Error(`Invalid filename: ${file}`)
|
||||
);
|
||||
const dir = `.${path.sep}`;
|
||||
t.throws(
|
||||
() =>
|
||||
log4js.configure({
|
||||
appenders: {
|
||||
file: {
|
||||
type: "fileSync",
|
||||
filename: dir
|
||||
}
|
||||
},
|
||||
categories: {
|
||||
default: { appenders: ["file"], level: "debug" }
|
||||
}
|
||||
}),
|
||||
new Error(`Filename is a directory: ${dir}`)
|
||||
);
|
||||
t.end();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user