<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="../rfc2629.xslt"?>
<!DOCTYPE rfc SYSTEM 'rfc2629.dtd' [
<!ENTITY rfc2119 PUBLIC '' 'bibxml/reference.RFC.2119.xml'>
<!ENTITY rfc5545 PUBLIC '' 'bibxml/reference.RFC.5545.xml'>
<!ENTITY rfc6350 PUBLIC '' 'bibxml/reference.RFC.6350.xml'>
]> 
<?rfc toc="yes"?>
<?rfc comments="yes"?>
<?rfc inline="yes"?>
<?rfc symrefs="yes"?>
<?rfc sortrefs="yes"?>
<?rfc compact="yes"?>
<?rfc subcompact="no"?>
<?rfc tocdepth="2"?>
<?rfc strict="yes"?>
<rfc category="std" ipr='trust200902' docName='draft-daboo-ical-vcard-parameter-encoding-02' updates="5545,6350">
    <front>
        <title abbrev="Parameter Encoding">Parameter Value Encoding in iCalendar and vCard</title>
        <author initials="C." surname="Daboo" fullname="Cyrus Daboo">
            <organization abbrev="Apple">
                Apple Inc.
            </organization>
            <address>
                <postal>
                    <street>
                        1 Infinite Loop
                    </street>
                    <city>
                        Cupertino
                    </city>
                    <region>
                        CA
                    </region>
                    <code> 95014 </code>
                    <country>
                        USA
                    </country>
                </postal>
                <email>
                    cyrus@daboo.name
                </email>
                <uri>
                    http://www.apple.com/
                </uri>
            </address>
        </author>
        <date />
        <area>Applications</area>
        <keyword>calendar</keyword>
        <keyword>contact</keyword>
        <abstract>
            <t>
              This specification updates the iCalendar and vCard data formats to allow parameter values to include certain characters forbidden by the existing specifications.
            </t>
        </abstract>
    </front>
    <middle>
        <section title='Introduction'>
            <t>
              The <xref target="RFC5545">iCalendar</xref> specification defines a standard way to describe calendar data. The <xref target="RFC6350">vCard</xref> specification defines a standard way to describe contact data. Both of these use a similar text-based data format. Each iCalendar and vCard data object can include "properties" which have "parameters" and a "value". The value of a "parameter" is typically a token or URI value, but a "generic" text value is also allowed. However, the syntax rules for both iCalendar and vCard prevent the use of a double-quote character or control characters in such values, though double-quote and some subset of control characters are allowed in the actual property values.
              </t>
              <t>
                As more and more extensions are being developed for these data formats, there is a need to allow at least double-quotes and line feeds to be included in parameter values. The \-escaping mechanism used for property text values is not defined for use with parameter values and cannot be easily used in a backwards compatible manner. This specification defines a new character escaping mechanism, compatible with existing parsers and chosen to minimise any impact on existing data.
            </t>
        </section>
        <section title='Conventions Used in This Document'>
            <t>
              The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in <xref target='RFC2119' />.
            </t>
        </section>
        <section title="Parameter Value Encoding Scheme">
            <t>
              This specification defines the ^ character (U+005E - Circumflex Accent) as an escape character in parameter values whose value type is defined using the "param-value" syntax element (Section 3.1 of <xref target="RFC5545">iCalendar</xref> and Section 3.3 of <xref target="RFC6350">vCard</xref>). The ^-escaping mechanism can be used when the value is either unquoted or quoted (i.e., whether or not the value is surrounded by double-quotes). When used, the combination of ^ plus one other character is interpreted as a single character as per the table below:</t>
            <texttable>
            <ttcol>Escape Sequence</ttcol>
            <ttcol>Character</ttcol>
            <c>^' (U+005E, U+0027)</c>
            <c>U+0022 (Quotation Mark)</c>
            <c>^n (U+005E, U+006E)</c>
            <c>U+000A (Line Feed)</c>
            <c>^^ (U+005E, U+005E)</c>
            <c>U+005E (Circumflex Accent)</c>
            </texttable>
            <t>
              When generating iCalendar or vCard parameter values, the characters in the second column above MUST be escaped using the sequence from the first column. When parsing iCalendar or vCard parameter values, the two character sequence from the first column MUST be replaced by the single character from the second column. If a ^ (U+005E) character is followed by any other character than the ones above, parsers SHOULD leave the ^ character in place.
            </t>
            <t>
              In addition to the escaping procedure outlined above, text parameter values MUST also have line break character sequences canonicalized into a single line feed (U+000A) character when the parameter value is generated. Specifically, any single carriage return character (U+000D) or the two character combination  of carriage return followed by line feed (U+000D, U+000A) MUST be mapped to ^n in the generated parameter value. When parsing a parameter value with ^n, clients can replace that with the appropriate line break character sequence for the system they are running on.
            </t>
            <section title="iCalendar Example" anchor="ics_example">
              <figure>
                <preamble>An "ATTENDEE" property with a "CN" parameter whose value includes two double-quote characters. The parameter value is not quoted as there are no characters in the value that would trigger quoting as required by iCalendar.</preamble>
                <artwork><![CDATA[
ATTENDEE;CN=George Herman ^'Babe^' Ruth:mailto:babe@example.com
]]></artwork>
              </figure>
              <figure>
                <preamble>The unescaped parameter value is</preamble>
                <artwork><![CDATA[
George Herman "Babe" Ruth
]]></artwork>
              </figure>
            </section>
            <section title="vCard Examples">
              <figure>
                <preamble>A "GEO" property with a "X-ADDRESS" parameter whose value includes several line feed characters. The parameter value is also quoted since it contains a comma which triggers quoting as required by vCard.</preamble>
                <artwork><![CDATA[
GEO;X-ADDRESS="Pittsburgh Pirates^n115 Federal St^nPitt
 sburgh, PA 15212":geo:40.446816,-80.00566
]]></artwork>
              </figure>
              <figure>
                <preamble>The unescaped parameter value is (where each line is terminated by a line break character sequence)</preamble>
                <artwork><![CDATA[
Pittsburgh Pirates
115 Federal St
Pittsburgh, PA 15212
]]></artwork>
              </figure>
            </section>
        </section>
        <section title='Security Considerations'>
            <t>
              There are no additional security issues beyond those of <xref target="RFC5545">iCalendar</xref> and <xref target="RFC6350">vCard</xref>.
            </t>
        </section>
        <section title='IANA Considerations'>
            <t>There are none.</t>
        </section>
        <section title='Acknowledgments'>
            <t>
              Thanks to Michael Angstadt, Mike Douglass, Barry Leiba, Simon Perreault for feedback on this specification.
            </t>
        </section>
    </middle>
    <back>
        <references title='Normative References'>
            &rfc2119; &rfc5545; &rfc6350;
        </references>
        <!--
        <references title='Informative References'>
        </references>
        -->

        <section title='Choice of Quoting Mechanism'>
          <t>Having recognized the need for escaping parameters values, the question is what mechanism to use? One obvious choice would be to adopt the \-escaping used for property values. However, that could not be used as-is, because it escapes a double-quote as the sequence of \ followed by double-quote. Consider what the example in <xref target="ics_example"/> might look like using \-escaping:</t>
              <figure><artwork><![CDATA[
ATTENDEE;CN="George Herman \"Babe\" Ruth":mailto:babe@example.com
]]></artwork></figure>

          <t>Existing iCalendar/vCard parsers know nothing about escape sequences in parameters. So they would parse the parameter value as:</t>
              <figure><artwork><![CDATA[
George Herman \
]]></artwork></figure>
          <t>i.e. the text between the first and second occurrence of a double-quote. However, the text after the second double-quote ought to be either a : or a ; (to delimit the parameter value from the following parameter or property) but is not - so the parser could legitimately throw an error at that point because the data is syntactically invalid. Thus for backwards compatibility reasons, a double-quote cannot be escaped using a sequence that itself includes a double-quote. Hence the choice of using a single-quote in this specification.</t>

          <t>Another option would be to use a form of \-escaping modified for use in parameter values only. However, some incorrect, non-interoperable use of \ in parameter values has been observed, and thus it is best to steer clear of that to achieve guaranteed, reliable interoperability. Also, given that double-quote gets changed to single-quote in the escape sequence for a parameter, but not for a value, it is better to not give the impression that the same escape mechanism (and thus code) can be used for both (which could lead to other issues such as an implementations incorrectly escaping a ; as \; as opposed to quoting the parameter value).</t>

          <t>The choice of ^ as the escape character was made based on the requirement that an ASCII symbol (non-alphanumeric) character be used, and it ought to be one least likely to be found in existing data.</t>
        </section>
        <section title="Change History (To be removed by RFC Editor before publication)">
            <t>
                Changes in -02:
                <list style='numbers'>
                  <t>Removed unnecessary HTAB escaping.</t>
                  <t>Added appendix to describe why ^ was chosen as the escape mechanism.</t>
                </list>
            </t>
            <t>
                Changes in -01:
                <list style='numbers'>
                  <t>Tweaked vCard example line-folding.</t>
                </list>
            </t>
        </section>
    </back>
</rfc>
