@@ -1268,14 +1268,36 @@ describe('class MongoLogger', async function () {
12681268
12691269 context ( 'when maxDocumentLength is non-zero' , function ( ) {
12701270 context ( 'when document has length greater than maxDocumentLength' , function ( ) {
1271- it ( 'truncates ejson string to length of maxDocumentLength + 3' , function ( ) {
1272- expect ( stringifyWithMaxLen ( largeDoc , DEFAULT_MAX_DOCUMENT_LENGTH ) ) . to . have . lengthOf (
1273- DEFAULT_MAX_DOCUMENT_LENGTH + 3
1274- ) ;
1271+ context ( 'when truncation does not occur mid-multibyte codepoint' , function ( ) {
1272+ it ( 'truncates ejson string to length of maxDocumentLength + 3' , function ( ) {
1273+ expect ( stringifyWithMaxLen ( largeDoc , DEFAULT_MAX_DOCUMENT_LENGTH ) ) . to . have . lengthOf (
1274+ DEFAULT_MAX_DOCUMENT_LENGTH + 3
1275+ ) ;
1276+ } ) ;
12751277 } ) ;
1278+
12761279 it ( 'ends with "..."' , function ( ) {
12771280 expect ( stringifyWithMaxLen ( largeDoc , DEFAULT_MAX_DOCUMENT_LENGTH ) ) . to . match ( / ^ .* \. \. \. $ / ) ;
12781281 } ) ;
1282+
1283+ context ( 'when truncation occurs mid-multibyte codepoint' , function ( ) {
1284+ const multiByteCodePoint = '\ud83d\ude0d' ; // heart eyes emoji
1285+ context ( 'when maxDocumentLength = 1 but greater than 0' , function ( ) {
1286+ it ( 'should return an empty string' , function ( ) {
1287+ expect ( stringifyWithMaxLen ( multiByteCodePoint , 1 , { relaxed : true } ) ) . to . equal ( '' ) ;
1288+ } ) ;
1289+ } ) ;
1290+
1291+ context ( 'when maxDocumentLength > 1' , function ( ) {
1292+ it ( 'should round down maxDocLength to previous codepoint' , function ( ) {
1293+ const randomStringMinusACodePoint = `random ${ multiByteCodePoint } random random${ multiByteCodePoint } ` ;
1294+ const randomString = `${ randomStringMinusACodePoint } ${ multiByteCodePoint } ` ;
1295+ expect (
1296+ stringifyWithMaxLen ( randomString , randomString . length - 1 , { relaxed : true } )
1297+ ) . to . equal ( `${ randomStringMinusACodePoint } ...` ) ;
1298+ } ) ;
1299+ } ) ;
1300+ } ) ;
12791301 } ) ;
12801302
12811303 context ( 'when document has length less than or equal to maxDocumentLength' , function ( ) {
@@ -1289,7 +1311,6 @@ describe('class MongoLogger', async function () {
12891311 / ^ .* \. \. \. /
12901312 ) ;
12911313 } ) ;
1292-
12931314 it ( 'produces valid relaxed EJSON' , function ( ) {
12941315 expect ( ( ) => {
12951316 EJSON . parse ( stringifyWithMaxLen ( smallDoc , DEFAULT_MAX_DOCUMENT_LENGTH ) ) ;
0 commit comments