Skip to content

Commit

Permalink
Fixes #26 – ensure that a word that ends with non-ascii char does not…
Browse files Browse the repository at this point in the history
… include trailing space. Bumped version to 0.2.18
  • Loading branch information
andris9 committed Oct 25, 2014
1 parent 906c2a2 commit b2225f1
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/mimelib.js
Expand Up @@ -381,7 +381,7 @@ module.exports.mimeFunctions = {
var decodedValue = convert((value || ""), "utf-8", fromCharset).toString("utf-8"),
encodedValue;

encodedValue = decodedValue.replace(/([^\s\u0080-\uFFFF]*[\u0080-\uFFFF]+[^\s\u0080-\uFFFF]*(?:\s+[^\s\u0080-\uFFFF]*[\u0080-\uFFFF]+[^\s\u0080-\uFFFF]*\s*)?)+/g, (function(str) {
encodedValue = decodedValue.replace(/([^\s\u0080-\uFFFF]*[\u0080-\uFFFF]+[^\s\u0080-\uFFFF]*(?:\s+[^\s\u0080-\uFFFF]*[\u0080-\uFFFF]+[^\s\u0080-\uFFFF]*\s*)?)+(?=\s|$)/g, (function(str) {
return str.length ? this.encodeMimeWord(str, encoding || "Q", maxLength, toCharset) : "";
}).bind(this));

Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,7 +1,7 @@
{
"name": "mimelib",
"description": "MIME functions to encode/decode e-mails etc.",
"version": "0.2.17",
"version": "0.2.18",
"author": "Andris Reinman",
"homepage": "http://github.com/andris9/mimelib",
"maintainers": [
Expand Down
11 changes: 8 additions & 3 deletions test/mimelib.js
Expand Up @@ -139,17 +139,22 @@ exports["Mime Words"] = {
"Ascii range": function(test){
var input1 = "метель\" вьюга",
input2 = "метель'вьюга",
input3 = 'Verão você vai adorar!',
output1 = "=?UTF-8?Q?=D0=BC=D0=B5=D1=82=D0=B5=D0=BB=D1=8C=22_?= =?UTF-8?Q?=D0=B2=D1=8C=D1=8E=D0=B3=D0=B0?=",
output2 = "=?UTF-8?Q?=D0=BC=D0=B5=D1=82=D0=B5=D0=BB=D1=8C'?= =?UTF-8?Q?=D0=B2=D1=8C=D1=8E=D0=B3=D0=B0?=";
output2 = "=?UTF-8?Q?=D0=BC=D0=B5=D1=82=D0=B5=D0=BB=D1=8C'?= =?UTF-8?Q?=D0=B2=D1=8C=D1=8E=D0=B3=D0=B0?=",
output3 = '=?UTF-8?Q?Ver=C3=A3o_voc=C3=AA?= vai adorar!';

test.equal(mimelib.encodeMimeWords(input1, "Q", 52), output1);
test.equal(mimelib.parseMimeWords(output1), input1);

test.equal(mimelib.encodeMimeWords(input2, "Q", 52), output2);
test.equal(mimelib.parseMimeWords(output2), input2);

test.equal(mimelib.encodeMimeWords(input3, "Q", 52), output3);
test.equal(mimelib.parseMimeWords(output3), input3);

test.done();
}
}
}

exports["Fold long line"] = function(test){
Expand Down

0 comments on commit b2225f1

Please sign in to comment.