Bug 1660134 - Correctly decode vCard 2.1 quoted-printable fields with multiple values. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D87678 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
6fb7d66b76
Коммит
66299b9df8
|
@ -13,6 +13,18 @@ const { ICAL } = ChromeUtils.import("resource:///modules/calendar/Ical.jsm");
|
|||
*/
|
||||
|
||||
var VCardUtils = {
|
||||
_decodeQuotedPrintable(value) {
|
||||
let bytes = [];
|
||||
for (let b = 0; b < value.length; b++) {
|
||||
if (value[b] == "=") {
|
||||
bytes.push(parseInt(value.substr(b + 1, 2), 16));
|
||||
b += 2;
|
||||
} else {
|
||||
bytes.push(value.charCodeAt(b));
|
||||
}
|
||||
}
|
||||
return new TextDecoder().decode(new Uint8Array(bytes));
|
||||
},
|
||||
_parse(vProps) {
|
||||
let vPropMap = new Map();
|
||||
for (let index = 0; index < vProps.length; index++) {
|
||||
|
@ -24,16 +36,13 @@ var VCardUtils = {
|
|||
params.encoding &&
|
||||
params.encoding.toUpperCase() == "QUOTED-PRINTABLE"
|
||||
) {
|
||||
let bytes = [];
|
||||
for (let b = 0; b < value.length; b++) {
|
||||
if (value[b] == "=") {
|
||||
bytes.push(parseInt(value.substr(b + 1, 2), 16));
|
||||
b += 2;
|
||||
} else {
|
||||
bytes.push(value.charCodeAt(b));
|
||||
if (Array.isArray(value)) {
|
||||
for (let i = 0; i < value.length; i++) {
|
||||
value[i] = this._decodeQuotedPrintable(value[i]);
|
||||
}
|
||||
} else {
|
||||
value = this._decodeQuotedPrintable(value);
|
||||
}
|
||||
value = new TextDecoder().decode(new Uint8Array(bytes));
|
||||
}
|
||||
|
||||
// Work out which type in typeMap, if any, this property belongs to.
|
||||
|
|
|
@ -122,6 +122,7 @@ add_task(async () => {
|
|||
SecondEmail: "other@invalid",
|
||||
});
|
||||
|
||||
// Quoted-printable handling.
|
||||
check("FN;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=74=C3=A9=24=74=20=23=31", {
|
||||
DisplayName: "té$t #1",
|
||||
});
|
||||
|
@ -131,4 +132,8 @@ add_task(async () => {
|
|||
DisplayName: "test 💩",
|
||||
}
|
||||
);
|
||||
check("N;CHARSET=UTF-8;ENCODING=QUOTED-PRINTABLE:=C5=82ast;=C6=92irst", {
|
||||
FirstName: "ƒirst",
|
||||
LastName: "łast",
|
||||
});
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче