bolorundurowb / vCardLib

📇 A .NET standard library for reading and writing vCard files
https://github.com/bolorundurowb/vCardLib/blob/master/README.md
MIT License
27 stars 15 forks source link

Handle newlines within fields #71

Open ManolisKoufidakis opened 1 month ago

ManolisKoufidakis commented 1 month ago

Hi, The code throws exception when parsing some vcards (like the one below) where there is a newline character within a field.

The exception is:

Error while reading vcard qr. Error: System.ArgumentOutOfRangeException: length ('-1') must be a non-negative value. (Parameter 'length')
Actual value was -1.
   at System.ArgumentOutOfRangeException.ThrowNegative[T](T value, String paramName)
   at System.ArgumentOutOfRangeException.ThrowIfNegative[T](T value, String paramName)
   at System.String.ThrowSubstringArgumentOutOfRange(Int32 startIndex, Int32 length)
   at System.String.Substring(Int32 startIndex, Int32 length)
   at vCardLib.Deserialization.FieldDeserializers.CustomFieldDeserializer.Read(String input)
   at vCardLib.Deserialization.vCardDeserializer.DeserializeV3(IReadOnlyCollection`1 vcardContent)
   at vCardLib.Deserialization.vCardDeserializer.Convert(String[] vcardContent)
   at vCardLib.Deserialization.vCardDeserializer.FromContent(String vcardContents)+MoveNext()
   at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)

A sample vcard is:

BEGIN:VCARD
VERSION:2.1
N:Test;Tester
FN:Tester Test
ORG:ACME India PVT LTD
TITLE:Technical Sales & Support 
South India
TEL;CELL:+91 22222 22222
TEL;WORK;VOICE:+91 222 22222222
ADR;WORK:;;J 123, ASD;Delhi;Bhosari;411026.;India
EMAIL;WORK;INTERNET:test@tests.com
URL:www.acme.com
END:VCARD
bolorundurowb commented 1 month ago

I'll check the RFC to see if rows are allowed to wrap, my understanding is that they are supposed to be escaped and quoted. Something like TITLE:"Technical Sales & Support \nSouth India"

henrihein commented 1 month ago

https://www.rfc-editor.org/rfc/rfc6350#section-3.2 Lines after a line-break that is part of the same field should start with whitespace (space or tab).