mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-10-31 16:13:15 +00:00
fix: decode escaped colons in imported vcard notes #1438
This commit is contained in:
@@ -220,6 +220,34 @@ describe("parseVCard", () => {
|
||||
);
|
||||
});
|
||||
|
||||
it("decodes the escaped colons Google Contacts writes (#1438)", () => {
|
||||
const vcf = [
|
||||
"BEGIN:VCARD",
|
||||
"VERSION:3.0",
|
||||
"FN:Test Example",
|
||||
"NOTE:Reference\\: fictional value\\nSecond line\\, with comma\\; and semicolon",
|
||||
"END:VCARD",
|
||||
].join("\r\n");
|
||||
|
||||
const result = parseVCard(vcf);
|
||||
expect(result[0].notes?.n0?.note).toBe(
|
||||
"Reference: fictional value\nSecond line, with comma; and semicolon"
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps an escaped backslash literal when an escapable character follows", () => {
|
||||
const vcf = [
|
||||
"BEGIN:VCARD",
|
||||
"VERSION:3.0",
|
||||
"FN:Paths",
|
||||
"NOTE:C:\\\\new\\\\:dir\\\\\\:x\\\\\\\\",
|
||||
"END:VCARD",
|
||||
].join("\r\n");
|
||||
|
||||
const result = parseVCard(vcf);
|
||||
expect(result[0].notes?.n0?.note).toBe("C:\\new\\:dir\\:x\\\\");
|
||||
});
|
||||
|
||||
it("allows group kind without name or email", () => {
|
||||
const vcf = [
|
||||
"BEGIN:VCARD",
|
||||
|
||||
+5
-5
@@ -204,12 +204,12 @@ function decodeQuotedPrintable(input: string, charset?: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
// One pass, so an escaped backslash can't pair up with the next character.
|
||||
// \: isn't a vCard escape, but Google Contacts writes it.
|
||||
function decodeValue(raw: string): string {
|
||||
return raw
|
||||
.replace(/\\n/gi, "\n")
|
||||
.replace(/\\,/g, ",")
|
||||
.replace(/\\;/g, ";")
|
||||
.replace(/\\\\/g, "\\");
|
||||
return raw.replace(/\\([\\,;:nN])/g, (_, c: string) =>
|
||||
c === "n" || c === "N" ? "\n" : c
|
||||
);
|
||||
}
|
||||
|
||||
function encodeValue(val: string): string {
|
||||
|
||||
Reference in New Issue
Block a user