Skip to content

Commit

Permalink
vCard phone-number escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
workgroupengineering authored and kewisch committed Oct 15, 2022
1 parent c7811df commit 9115c5d
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
13 changes: 13 additions & 0 deletions lib/ical/design.js
Original file line number Diff line number Diff line change
Expand Up @@ -742,6 +742,19 @@ 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
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", "[email protected]" ],
[ "email", { "type": "WORK" }, "text", "[email protected]" ],
[ "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:[email protected]
EMAIL;TYPE=WORK:[email protected]
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

0 comments on commit 9115c5d

Please sign in to comment.