Skip to content

fix multiple emojis in a row causing additional empty tokens being added #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/rfc2047.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions test/rfc2047.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
);
});

Expand Down