Skip to content

Commit efcecb9

Browse files
committed
Merge branch 'bugfix/CLDSRV-830' into q/9.2
2 parents 68c9f3c + 23e383a commit efcecb9

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

lib/utilities/serverAccessLogger.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,11 @@ function logServerAccess(req, res) {
416416
userName: params.analyticsUserName ?? undefined,
417417
httpMethod: req.method ?? undefined,
418418
bytesDeleted: params.analyticsBytesDeleted ?? undefined,
419-
bytesReceived: req.parsedContentLength ?? undefined,
419+
bytesReceived: Number.isInteger(req.parsedContentLength) ? req.parsedContentLength : undefined,
420420
bodyLength: req.headers['content-length'] !== undefined
421421
? parseInt(req.headers['content-length'], 10)
422422
: undefined,
423-
contentLength: req.parsedContentLength ?? undefined,
423+
contentLength: Number.isInteger(req.parsedContentLength) ? req.parsedContentLength : undefined,
424424
// eslint-disable-next-line camelcase
425425
elapsed_ms: calculateElapsedMS(params.startTime, params.onCloseEndTime) ?? undefined,
426426

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenko/cloudserver",
3-
"version": "9.2.14",
3+
"version": "9.2.15",
44
"description": "Zenko CloudServer, an open-source Node.js implementation of a server handling the Amazon S3 protocol",
55
"main": "index.js",
66
"engines": {

tests/unit/utils/serverAccessLogger.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,29 @@ describe('serverAccessLogger utility functions', () => {
11221122
assert.strictEqual(loggedData.errorCode, 'NoSuchKey');
11231123
assert.strictEqual('errorCode' in loggedData, true);
11241124
});
1125+
1126+
it('should omit NaN fields from log output', () => {
1127+
setServerAccessLogger(mockLogger);
1128+
const req = {
1129+
serverAccessLog: {},
1130+
headers: {},
1131+
parsedContentLength: NaN, // Simulates Number.parseInt('', 10)
1132+
socket: {},
1133+
};
1134+
const res = {
1135+
serverAccessLog: {},
1136+
getHeader: () => null,
1137+
};
1138+
1139+
logServerAccess(req, res);
1140+
1141+
assert.strictEqual(mockLogger.write.callCount, 1);
1142+
const loggedData = JSON.parse(mockLogger.write.firstCall.args[0].trim());
1143+
1144+
// NaN values should be omitted from the log output
1145+
assert.strictEqual('bytesReceived' in loggedData, false);
1146+
assert.strictEqual('contentLength' in loggedData, false);
1147+
});
11251148
});
11261149
});
11271150

0 commit comments

Comments
 (0)