Comparing version 4.0.0 to 4.0.1
@@ -223,2 +223,3 @@ /* global unescape */ | ||
let previousTokenWasEncodedWord = false; // Consecutive encoded words must have a space between them, so this state must be kept | ||
let nextTokenMustBeEncoded = false; | ||
let previousTokenWasWhitespaceFollowingEncodedWord = false; | ||
@@ -229,3 +230,3 @@ let result = ''; | ||
let token = tokens[i]; | ||
if (unsafeTokenRegExp.test(token)) { | ||
if (unsafeTokenRegExp.test(token) || (token && nextTokenMustBeEncoded)) { | ||
const matchQuotesAtBeginning = token.match(/^"+/); | ||
@@ -251,2 +252,3 @@ if (matchQuotesAtBeginning) { | ||
if (token.length > maxNumCharsPerEncodedWord) { | ||
nextTokenMustBeEncoded = true; | ||
const chars = [...token]; | ||
@@ -259,2 +261,4 @@ tokens.splice( | ||
token = chars.slice(0, maxNumCharsPerEncodedWord).join(''); | ||
} else { | ||
nextTokenMustBeEncoded = false; | ||
} | ||
@@ -261,0 +265,0 @@ |
{ | ||
"name": "rfc2047", | ||
"version": "4.0.0", | ||
"version": "4.0.1", | ||
"description": "Encode and decode rfc2047 (MIME encoded words)", | ||
@@ -5,0 +5,0 @@ "main": "lib/rfc2047.js", |
@@ -67,2 +67,10 @@ const unexpected = require('unexpected'); | ||
it('should handle single word encoding, containing one non ASCII-character', () => { | ||
expect( | ||
'ABCDE-München <abcde-muenchen@example.org>', | ||
'to encode back and forth to', | ||
'=?utf-8?Q?ABCDE-M=C3=BC?= =?utf-8?Q?nchen?= <abcde-muenchen@example.org>' | ||
); | ||
}); | ||
it('should use an UTF-8 encoded word when a character is not in iso-8859-1', () => { | ||
@@ -142,3 +150,3 @@ expect( | ||
'to encode back and forth to', | ||
'=?utf-8?Q?test=5F=EF=BF=BD=2Ed?=ocx' | ||
'=?utf-8?Q?test=5F=EF=BF=BD=2Ed?= =?utf-8?Q?ocx?=' | ||
); | ||
@@ -145,0 +153,0 @@ }); |
29811
615