diff --git a/lib/rfc2047.js b/lib/rfc2047.js index 59a01fb..95ed190 100644 --- a/lib/rfc2047.js +++ b/lib/rfc2047.js @@ -246,7 +246,8 @@ rfc2047.encode = (text) => { } // Word contains at least one header unsafe char, an encoded word must be created. - if (token.length > maxNumCharsPerEncodedWord) { + // Don't check string length directly as emojis can be longer than 1 char. + if ([...token].length > maxNumCharsPerEncodedWord) { nextTokenMustBeEncoded = true; const chars = [...token]; tokens.splice( diff --git a/test/rfc2047.js b/test/rfc2047.js index 3389f34..0f26240 100644 --- a/test/rfc2047.js +++ b/test/rfc2047.js @@ -50,9 +50,9 @@ describe('rfc2047', () => { // https://github.com/One-com/rfc2047/issues/11 it('should handle a string with multiple emojis in a row', () => { expect( - 'Seven hills😍🦌', + 'Seven hills 😍🦌😍🦌😍 no extra spaces', 'to encode back and forth to', - 'Seven =?utf-8?Q?hills=F0=9F=98=8D=F0=9F=A6=8C?=' + 'Seven hills =?utf-8?Q?=F0=9F=98=8D=F0=9F=A6=8C=F0=9F=98=8D=F0=9F=A6=8C=F0=9F=98=8D?= no extra spaces' ); });