How to encode newlines in vCard 4.0 parameter values: ^n or \n?

537 views Asked by At

The vCard 4.0 RFC 6350 says that Newlines in property parameter values must be encoded as \n (at least for LABEL parameter of ADR property):

  The property can also include a "LABEL" parameter to present a
  delivery address label for the address.  Its value is a plain-text
  string representing the formatted address.  Newlines are encoded
  as \n, as they are for property values.


  ADR;GEO="geo:12.3457,78.910";LABEL="Mr. John Q. Public, Esq.\n
  Mail Drop: TNE QB\n123 Main Street\nAny Town, CA  91921-1234\n
  U.S.A.":;;123 Main Street;Any Town;CA;91921-1234;U.S.A.

However vCard 4.0 RFC 6350 is updated by 'Parameter Value Encoding in iCalendar and vCard' RFC 6868, which says:

  formatted text line breaks are encoded into ^n (U+005E, U+006E)

  GEO;X-ADDRESS="Pittsburgh Pirates^n115 Federal St^nPitt
  sburgh, PA 15212":geo:40.446816,-80.00566
  being used

How do I encode newlines in vCard 4.0 parameter values as \n or as ^n?

1

There are 1 answers

0
hnh On

Look at the actual grammar:

param-value = *SAFE-CHAR / DQUOTE *QSAFE-CHAR DQUOTE

vCard/iCalendar (unfortunately) does not support generic escaping in property attribute values. As mentioned in RFC 6868:

The \-escaping mechanism used for property text values is not defined for use with parameter values

(which is the whole point of RFC 6868).

LABEL is special and explicitly spec'ed to support \n:

The property can also include a "LABEL" parameter to present a delivery address label for the address. Its value is a plain-text string representing the formatted address. Newlines are encoded as \n, as they are for property values.

This is just for LABEL.

To answer your question: "How do I encode newlines in vCard 4.0 parameter values as \n or as ^n?"

You first look whether the value of the parameter is spec'ed in a special way, like LABEL. If so, encode it as described for the parameter. If it isn't, encode it via ^.