escapingnewlinevcf-vcardcarddav

How do I escape new line in vCard 4.0 values?


I see some inconsistency in vCard 4.0 RFC 6350 new line escaping rules. Section 3.4 says:

NEWLINE (U+000A) characters in values MUST be encoded by two characters: a BACKSLASH followed by either an 'n' (U+006E) or an 'N' (U+004E).

I assume that I should replace not only the LF (U+000A) character, but CRLF sequence. This is how it was in vCard 3.0 RFC 2426 and the difference from vCard 2.1.

Should I replace CRLF sequence or only LF character according to vCard 4.0 specification?


Solution

  • In vCard 4.0, the newline escape sequence is \n. If the local operating system uses CRLF as its newline sequence, the CR and LF characters are both replaced with a single \n.

    When parsing a vCard, the \n should be replaced with whatever the local operating system's newline sequence is.