This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
vcard.parse.spec.js
186 lines (150 loc) · 6.03 KB
/
vcard.parse.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
var vCard = require('../lib/vcard');
describe('vCard.parse', function () {
it('Should ignore vCard start and end tags', function () {
var raw = 'BEGIN:VCARD\r\nEND:VCARD',
card = vCard.parse(raw);
expect(card).toEqual({});
});
it('Should parse simple vcard lines', function () {
var raw = 'FN:Forrest Gump',
card = vCard.parse(raw);
expect(card.fn).toEqual([{value: 'Forrest Gump'}]);
});
it('Should parse line with complex properties', function () {
var raw = 'N:Gump;Forrest;;Mr.;',
card = vCard.parse(raw);
expect(card.n).toEqual([{
value: [
'Gump', 'Forrest', '', 'Mr.', ''
]
}]);
});
it('Should parse vcard with repeated properties', function () {
var raw = 'FN:Forrest Gump\nFN:Other Gump',
card = vCard.parse(raw);
expect(card.fn).toEqual([
{value: 'Forrest Gump'},
{value: 'Other Gump'}
]);
});
it('Should parse line with metadata', function () {
var raw = 'TEL;TYPE=HOME:78884545247',
card = vCard.parse(raw);
expect(card.tel).toEqual([
{value: '78884545247', meta: {type: ['HOME']}}
]);
});
it('Should parse line with multiple metadata', function () {
var raw = 'TEL;TYPE=HOME;PREF=1:78884545247',
card = vCard.parse(raw);
expect(card.tel).toEqual([
{value: '78884545247', meta: {type: ['HOME'], pref: ['1']}}
]);
});
it('Should parse line with multiple values of one metadata field', function () {
var raw = 'TEL;TYPE=HOME;TYPE=CELL:78884545247',
card = vCard.parse(raw);
expect(card.tel).toEqual([
{value: '78884545247', meta: {type: ['HOME', 'CELL']}}
]);
});
it('Should parse line with namespace', function () {
var raw = 'item1.EMAIL;TYPE=INTERNET:[email protected]',
card = vCard.parse(raw);
expect(card.email).toEqual([
{value: '[email protected]', namespace: 'item1', meta: {type: ['INTERNET']}}
]);
});
it('Should parse multiline properties (when first symbol is space)', function () {
var raw = 'PHOTO;ENCODING=b;TYPE=JPEG:THIS/IS/SHITTY/BASE64\n' +
' ENCODED/PHOTO',
card = vCard.parse(raw);
expect(card.photo).toEqual([
{value: 'THIS/IS/SHITTY/BASE64ENCODED/PHOTO', meta: {encoding: ['b'], type: ['JPEG']}}
]);
});
it('Should parse multiline properties (when first symbol is tab)', function () {
var raw = 'PHOTO;ENCODING=b;TYPE=JPEG:THIS/IS/SHITTY/BASE64\n' +
'\tENCODED/PHOTO',
card = vCard.parse(raw);
expect(card.photo).toEqual([
{value: 'THIS/IS/SHITTY/BASE64ENCODED/PHOTO', meta: {encoding: ['b'], type: ['JPEG']}}
]);
});
it('Should parse properties with \\n symbol', function () {
var raw = 'BEGIN:VCARD\nADR:Hello\\nmy\\naddress\nEND:VCARD',
card = vCard.parse(raw);
expect(card.adr).toEqual([
{value: 'Hello\nmy\naddress'}
]);
});
it('Should parse properties with escaped semicolon, colon and backslash symbols', function () {
var raw = 'ADR:\\1\\;2\\,3\\;;;;;',
card = vCard.parse(raw);
expect(card.adr).toEqual([
{value: ['\\1;2,3;','','','','']}
]);
});
it('Should parse properties with escaped semicolon, colon and backslash symbols in meta value', function () {
var raw = 'TEL;TYPE=HO\\;\\,\\ME;PREF=1:78884545247',
card = vCard.parse(raw);
expect(card.tel).toEqual([
{value: '78884545247', meta: {type: ['HO;,\\ME'], pref: ['1']}}
]);
});
it('Should parse url in property correctly', function () {
var raw = 'URL:http://akitov.info',
card = vCard.parse(raw);
expect(card.url).toEqual([
{value: 'http://akitov.info'}
]);
});
it('Should not convert case of extended property names', function () {
var raw = 'item1.X-ABLabel:super',
card = vCard.parse(raw);
expect(card['X-ABLabel']).toEqual([
{value: 'super', namespace: 'item1'}
]);
});
it('Should not create empty meta keys', function () {
var raw = 'PHOTO;X-ABCROP-RECTANGLE=ABClipRect_1&0&0&671&671&Nh68TCRv7GErj8P8mk8qCA==;',
card = vCard.parse(raw);
expect(card['photo']).toEqual([
{ value : '', meta : { 'x-abcrop-rectangle' : [ 'ABClipRect_1&0&0&671&671&Nh68TCRv7GErj8P8mk8qCA' ] } }
]);
});
it('Should properly parse multi line PHOTO properties', function () {
var raw = 'PHOTO;X-ABCROP-RECTANGLE=ABClipRect_1&0&0&671&671&Nh68TCRv7GErj8P8mk8qCA==;\n' +
' ENCODING=b;TYPE=JPEG:/9j/4AAQSkZJRgABAQEASABIAAD/4QBARXhpZgAATU0AKgAAAAgAA',
card = vCard.parse(raw);
expect(card['photo']).toEqual([
{
value: '/9j/4AAQSkZJRgABAQEASABIAAD/4QBARXhpZgAATU0AKgAAAAgAA',
meta: {
encoding: ['b'],
type: ['JPEG'],
'x-abcrop-rectangle': ['ABClipRect_1&0&0&671&671&Nh68TCRv7GErj8P8mk8qCA']
}
}
]);
});
it('Should parse props with semicolon-separated values', function () {
var raw = 'ORG:ABC\, Inc.;North American Division;Marketing',
card = vCard.parse(raw);
expect(card['org']).toEqual([
{ value: ['ABC, Inc.', 'North American Division', 'Marketing'] }
]);
});
it('Should parse props with comma-separated values', function () {
var raw = 'NICKNAME:Jim,Jimmie',
card = vCard.parse(raw);
expect(card['nickname']).toEqual([
{ value: ['Jim', 'Jimmie'] }
]);
});
it('Should parse vcard with empty first name', function () {
var raw = 'FN:',
card = vCard.parse(raw);
expect(card.fn).toEqual([{value: ''}]);
});
});