<?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 rfc6321 PUBLIC '' 'bibxml/reference.RFC.6321.xml'>
<!ENTITY rfc6350 PUBLIC '' 'bibxml/reference.RFC.6350.xml'>
<!ENTITY rfc6351 PUBLIC '' 'bibxml/reference.RFC.6351.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-04' updates="5545,6321,6350,6351">
    <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 data formats for iCalendar (RFC 5545) and vCard (RFC 6350) 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).
            </t>
            <t>
              When generating iCalendar or vCard parameter values the following applies:
              <list style="symbols">
                <t>formatted text line breaks are encoded into ^n (U+005E, U+006E)</t>
                <t>the ^ character (U+005E) is encoded into ^^ (U+005E, U+005E)</t>
                <t>the " character (U+0022) is encoded into ^' (U+005E, U+0027)</t>
              </list>
            </t>
            <t>
              When parsing iCalendar or vCard parameter values the following applies:
              <list style="symbols">
                <t>the character sequence ^n (U+005E, U+006E) is decoded into an appropriate formatted line break for the system being run on</t>
                <t>the character sequence ^^ (U+005E, U+005E) is decoded into the ^ character (U+005E)</t>
                <t>the character sequence ^' (U+005E, U+0027) is decoded into the " character (U+0022)</t>
                <t>if a ^ (U+005E) character is followed by any other character than the ones above, parsers MUST leave both the ^ and the following character in place</t>
              </list>
            </t>
            <t>
              When converting between iCalendar and vCard text-based data formats and alternative data-format representations such as XML (as described in <xref target="RFC6321"/> and <xref target="RFC6351"/> respectively), implementations MUST ensure that parameter value escape sequences are generated correctly in the text-based format and are decoded when the parameter values appear in the alternate data formats.
            </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,
              Tim Bray,
              Mike Douglass,
              Barry Leiba,
              Simon Perreault,
              and Pete Resnick,
              for feedback on this specification.
            </t>
        </section>
    </middle>
    <back>
        <references title='Normative References'>
            &rfc2119; &rfc5545; &rfc6321; &rfc6350; &rfc6351;
        </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 -03:
                <list style='numbers'>
                  <t>Tweak wording and change SHOULD to MUST for leaving ^+any other character sequences unchanged.</t>
                  <t>Added paragraph on interaction with other data-format representations such as XML.</t>
                </list>
            </t>
            <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>
