Bug 1800305 - Fix importing .vcf file with \r\r\n as line breaks. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D162082 --HG-- extra : amend_source : 3702cf3af4de2b5e52981847b05164c59bc7e338
This commit is contained in:
Родитель
6dc4dec7f7
Коммит
3e0746c440
|
@ -233,10 +233,9 @@ class AddrBookFileImporter {
|
|||
].getService(Ci.nsIMsgVCardService);
|
||||
|
||||
let content = await IOUtils.readUTF8(this._sourceFile.path);
|
||||
let lines = content
|
||||
.trim()
|
||||
.replaceAll("\r\n", "\n")
|
||||
.split("\n");
|
||||
// According to rfc6350, \r\n should be used as line break.
|
||||
let sep = content.includes("\r\n") ? "\r\n" : "\n";
|
||||
let lines = content.trim().split(sep);
|
||||
|
||||
let totalLines = lines.length;
|
||||
let currentLine = 0;
|
||||
|
@ -248,7 +247,7 @@ class AddrBookFileImporter {
|
|||
continue;
|
||||
}
|
||||
|
||||
if (line.toLowerCase() == "begin:vcard") {
|
||||
if (line.toLowerCase().trimEnd() == "begin:vcard") {
|
||||
if (record.length) {
|
||||
throw Components.Exception(
|
||||
"Expecting END:VCARD but got BEGIN:VCARD",
|
||||
|
@ -266,7 +265,7 @@ class AddrBookFileImporter {
|
|||
|
||||
record.push(line);
|
||||
|
||||
if (line.toLowerCase() == "end:vcard") {
|
||||
if (line.toLowerCase().trimEnd() == "end:vcard") {
|
||||
this._targetDirectory.addCard(
|
||||
vcardService.vCardToAbCard(record.join("\n") + "\n")
|
||||
);
|
||||
|
|
|
@ -92,6 +92,14 @@
|
|||
"PrimaryEmail": "jane.doe@genericemail.invalid"
|
||||
}
|
||||
],
|
||||
"dos_vcard_import": [
|
||||
{
|
||||
"DisplayName": "Name Surname",
|
||||
"FirstName": "Name",
|
||||
"LastName": "Surname",
|
||||
"PrimaryEmail": "example@gmail.com"
|
||||
}
|
||||
],
|
||||
"csv_import": [
|
||||
{
|
||||
"DisplayName": "John Doe",
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
BEGIN:VCARD
|
||||
VERSION:3.0
|
||||
N:Surname;Name;;;
|
||||
FN:Name Surname
|
||||
EMAIL;type=INTERNET;type=HOME:example@gmail.com
|
||||
END:VCARD
|
|
@ -110,6 +110,15 @@ add_task(async function test_importVCardFile() {
|
|||
);
|
||||
});
|
||||
|
||||
/** Test importing .vcf file with \r\r\n as line breaks works. */
|
||||
add_task(async function test_importDosVCardFile() {
|
||||
return test_importAbFile(
|
||||
"vcard",
|
||||
"resources/dos_vcard_addressbook.vcf",
|
||||
"dos_vcard_import"
|
||||
);
|
||||
});
|
||||
|
||||
/** Test importing .ldif file works. */
|
||||
add_task(async function test_importLdifFile() {
|
||||
return test_importAbFile(
|
||||
|
|
Загрузка…
Ссылка в новой задаче