<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>29216</bug_id>
          
          <creation_ts>2015-10-21 09:47:42 +0000</creation_ts>
          <short_desc>JSON Conversion: Handling of surrogate pairs</short_desc>
          <delta_ts>2016-03-22 10:03:53 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>XPath / XQuery / XSLT</product>
          <component>Functions and Operators 3.1</component>
          <version>Candidate Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Christian Gruen">christian.gruen</reporter>
          <assigned_to name="Michael Kay">mike</assigned_to>
          
          
          <qa_contact name="Mailing list for public feedback on specs from XSL and XML Query WGs">public-qt-comments</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>123816</commentid>
    <comment_count>0</comment_count>
    <who name="Christian Gruen">christian.gruen</who>
    <bug_when>2015-10-21 09:47:42 +0000</bug_when>
    <thetext>I believe that the parsing of surrogate pairs in the JSON conversion process needs some clarification. In the current &quot;escape&quot; option rules for fn:parse-json and fn:json-to-xml, it is only insinuated that surrogate pairs need to be considered as well: &quot;(for example, unpaired surrogates)&quot;, &quot;This includes codepoints representing unpaired surrogates&quot;.

But I am wondering what is going to happen if a high surrogate is found that is not followed by a valid low surrogate. The following query...

  fn:parse-json(&apos;&quot;\uD800\uD83C\uDC1C&quot;&apos;, map { &apos;escape&apos;: true() })

might return one of the following results:

  a) \uD800, followed by the surrogate pair for U+1F01C, or
  b) \uD800\uD83C\uDC1C

Intuitively, I would expect a) to be correct: As \uD83C is no valid low surrogate, it is not combined with the high surrogate. b) would be correct if \uD83C was interpreted as low surrogate. As a result, \uDC1C is then invalid as well.

Any thoughts? Maybe the parsing of surrogate pairs is already standardized somewhere else (I couldn&apos;t find anything so far)?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>123832</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-10-21 22:25:46 +0000</bug_when>
    <thetext>RFC 7159 section 8.2 says, pragmatically:

   However, the ABNF in this specification allows member names and
   string values to contain bit sequences that cannot encode Unicode
   characters; for example, &quot;\uDEAD&quot; (a single unpaired UTF-16
   surrogate).  Instances of this have been observed, for example, when
   a library truncates a UTF-16 string without checking whether the
   truncation split a surrogate pair.  The behavior of software that
   receives JSON texts containing such values is unpredictable; for
   example, implementations might return different values for the length
   of a string value or even suffer fatal runtime exceptions.

Since the JSON RFC says the effects of doing this kind of thing are unpredictable, I really don&apos;t think it&apos;s necessary that we pin it down any further than we do at the moment.

I would also tend to expect your option (a), but I really don&apos;t think it matters greatly if the software does something else. Anyone who puts unpaired surrogates in their data deserves what they get.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>123965</commentid>
    <comment_count>2</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2015-10-27 16:31:01 +0000</bug_when>
    <thetext>We decided to add a note to the effect:

Unpaired surrogates don&apos;t cause an error, but the exact treatment might depend on the parsing algorithm used.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>