Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] vCard phone-number escaping #517

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 13 additions & 4 deletions lib/ical/design.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,18 @@ const vcardValues = extend(commonValues, {
timestamp: icalValues['date-time'],
"language-tag": {
matches: /^[a-zA-Z0-9-]+$/ // Could go with a more strict regex here
},
"phone-number": {
fromICAL: function(aValue) {
return Array.from(aValue).filter(function(c) {
return c === '\\' ? undefined : c;
}).join('');
},
toICAL: function(aValue) {
return Array.from(aValue).map(function(c) {
return c === ',' || c === ";" ? '\\' + c : c;
}).join('');
}
}
});

Expand Down Expand Up @@ -798,10 +810,7 @@ let vcard3Values = extend(commonValues, {
binary: icalValues.binary,
date: vcardValues.date,
"date-time": vcardValues["date-time"],
"phone-number": {
// TODO
/* ... */
},
"phone-number": vcardValues["phone-number"],
uri: icalValues.uri,
text: icalValues.text,
time: icalValues.time,
Expand Down
3 changes: 2 additions & 1 deletion test/parse_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ suite('parserv2', function() {
'vcard.vcf',
'vcard_author.vcf',
'vcard3.vcf',
'vcard_grouped.vcf'
'vcard_grouped.vcf',
'escape_semicolon.vcf'
];

list.forEach(function(path) {
Expand Down
26 changes: 26 additions & 0 deletions test/parser/escape_semicolon.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[
"vcard",
[
[ "version", {}, "text", "3.0" ],
[ "prodid", {}, "text", "-//Sabre//Sabre VObject 4.1.6//EN" ],
[ "uid", {}, "text", "ad612c16-fe12-4ec5-abf6-49998ee5ab88" ],
[ "fn", {}, "text", "First Last NextCloud" ],
[ "adr", { "type": "HOME" }, "text", [ "PO", "Street 2", "Street", "City", "AL", "zip", "Germany" ] ],
[ "adr", { "type": "WORK" }, "text", [ "PO W", "Street 2 W", "Street W", "City Work", "AL work", "zip Work", "Germany work" ] ],
[ "email", { "type": "HOME" }, "text", "home@gmx.de" ],
[ "email", { "type": "WORK" }, "text", "work@gmx.de" ],
[ "tel", { "type": [ "HOME", "VOICE" ] }, "phone-number", "11111111" ],
[ "tel", { "type": "CELL" }, "phone-number", "205333" ],
[ "tel", { "type": ["WORK", "FAX" ] }, "phone-number", "205246;;,;" ],
[ "tel", { "type": ["WORK", "VOICE" ] }, "phone-number", "222222" ],
[ "org", {}, "text", "Firma" ],
[ "bday", {}, "date-time", "2019-02-10T00:00:33" ],
[ "nickname", {}, "text", "Hugo" ],
[ "x-abdate", {"group": "item1"}, "date-and-or-time", "20190220T000035" ],
[ "x-ablabel", {"group": "item1"}, "unknown", "_$!<Anniversary>!$_" ],
[ "x-anniversary", {}, "date-and-or-time", "20190220T000035" ],
[ "categories", {}, "text", "Test-Kontakte" ],
[ "rev", {}, "date-time", "2019-10-08T17:05:14Z" ]
],
[]
]
23 changes: 23 additions & 0 deletions test/parser/escape_semicolon.vcf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
BEGIN:VCARD
VERSION:3.0
PRODID:-//Sabre//Sabre VObject 4.1.6//EN
UID:ad612c16-fe12-4ec5-abf6-49998ee5ab88
FN:First Last NextCloud
ADR;TYPE=HOME:PO;Street 2;Street;City;AL;zip;Germany
ADR;TYPE=WORK:PO W;Street 2 W;Street W;City Work;AL work;zip Work;Germany w
ork
EMAIL;TYPE=HOME:home@gmx.de
EMAIL;TYPE=WORK:work@gmx.de
TEL;TYPE="HOME,VOICE":11111111
TEL;TYPE=CELL:205333
TEL;TYPE="WORK,FAX":205246\;\;\,\;
TEL;TYPE="WORK,VOICE":222222
ORG:Firma
BDAY:20190210T000033
NICKNAME:Hugo
ITEM1.X-ABDATE;VALUE=DATE-AND-OR-TIME:20190220T000035
ITEM1.X-ABLABEL:_$!<Anniversary>!$_
X-ANNIVERSARY;VALUE=DATE-AND-OR-TIME:20190220T000035
CATEGORIES:Test-Kontakte
REV:20191008T170514Z
END:VCARD