diff options
Diffstat (limited to 'jstests/core/escaped-logs.js')
-rw-r--r-- | jstests/core/escaped-logs.js | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/jstests/core/escaped-logs.js b/jstests/core/escaped-logs.js new file mode 100644 index 00000000000..223c003d22a --- /dev/null +++ b/jstests/core/escaped-logs.js @@ -0,0 +1,18 @@ +// Test escaping of user provided data in logs +// @tags: [requires_non_retryable_commands] + +(function() { + 'use strict'; + load('jstests/libs/check_log.js'); + + const mongo = db.getMongo(); + const admin = mongo.getDB('admin'); + + // Test a range of characters sent to the global log + for (let i = 1; i < 256; ++i) { + const msg = "Hello" + String.fromCharCode(i) + "World"; + assert.commandWorked(admin.runCommand({logMessage: msg})); + const escmsg = msg.replace("\r", "\\r").replace("\n", "\\n"); + checkLog.contains(mongo, "logMessage: " + escmsg); + } +})(); |