# HG changeset patch # User Jorg K # Date 1512682067 -3600 # Thu Dec 07 22:27:47 2017 +0100 # Node ID 8bc93e746d8217a13c77f44565ad68a03da63882 # Parent 6388ba6bd50f3f209ec38ded38a853cd7feeafe5 Bug 1423432 - remove null characters from headers (idea by jcranmer). r=mkmelin a=jorgk diff --git a/mailnews/mime/src/mimeJSComponents.js b/mailnews/mime/src/mimeJSComponents.js --- a/mailnews/mime/src/mimeJSComponents.js +++ b/mailnews/mime/src/mimeJSComponents.js @@ -220,18 +220,23 @@ var EmailGroup = { }; // A helper method for parse*Header that takes into account the desire to // preserve group and also tweaks the output to support the prototypes for the // XPIDL output. function fixArray(addresses, preserveGroups, count) { function resetPrototype(obj, prototype) { let prototyped = Object.create(prototype); - for (var key of Object.getOwnPropertyNames(obj)) - prototyped[key] = obj[key]; + for (let key of Object.getOwnPropertyNames(obj)) { + if (typeof obj[key] == "string") { + prototyped[key] = obj[key].replace(/\x00/g, ''); + } else { + prototyped[key] = obj[key]; + } + } return prototyped; } let outputArray = []; for (let element of addresses) { if ('group' in element) { // Fix up the prototypes of the group and the list members element = resetPrototype(element, EmailGroup); element.group = element.group.map(e => resetPrototype(e, Mailbox)); diff --git a/mailnews/mime/test/unit/test_nsIMsgHeaderParser5.js b/mailnews/mime/test/unit/test_nsIMsgHeaderParser5.js --- a/mailnews/mime/test/unit/test_nsIMsgHeaderParser5.js +++ b/mailnews/mime/test/unit/test_nsIMsgHeaderParser5.js @@ -38,16 +38,25 @@ function run_test() { [{name: "foo\u00D0 bar", email: "foo@bar.invalid"}, {name: "\u00C3\u00B6foo", email: "ghj@foo.invalid"}], [{name: "foo\uFFFD bar", email: "foo@bar.invalid"}, {name: "\u00F6foo", email: "ghj@foo.invalid"}]], // Bug 961564 ["someone <>", [{name: "someone", email: ""}], [{name: "someone", email: ""}]], + // Bug 1423432: Encoded strings with null bytes, + // in base64 a single null byte can be encoded as AA== to AP==. + // parseEncodedHeader will remove the nullbyte. + ["\"null=?UTF-8?Q?=00?=byte\" ", + [{name: "null=?UTF-8?Q?=00?=byte", email: "nullbyte@example.com"}], + [{name: "nullbyte", email: "nullbyte@example.com"}]], + ["\"null=?UTF-8?B?AA==?=byte\" ", + [{name: "null=?UTF-8?B?AA==?=byte", email: "nullbyte@example.com"}], + [{name: "nullbyte", email: "nullbyte@example.com"}]], ]; for (let check of checks) { equalArrays(MailServices.headerParser.parseDecodedHeader(check[0]), check[1]); equalArrays(MailServices.headerParser.parseEncodedHeader(check[0], "UTF-8"), check[2]); }