<?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>9808</bug_id>
          
          <creation_ts>2010-05-26 15:37:30 +0000</creation_ts>
          <short_desc>[FO] fn:QName $paramUri need not be a valid xs:anyURI</short_desc>
          <delta_ts>2012-03-27 23:25:41 +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 1.0</component>
          <version>Recommendation</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc>http://www.w3.org/TR/xquery-operators/#func-QName</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="Tim Mills">tim</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>35837</commentid>
    <comment_count>0</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2010-05-26 15:37:30 +0000</bug_when>
    <thetext>Given the declarations from F&amp;O:

fn:QName($paramURI as xs:string?, $paramQName as xs:string) as xs:QName

fn:namespace-uri-from-QName($arg as xs:QName?) as xs:anyURI?

consider the query

let $uri := &apos;http://www.example.com/%gg/this-is-not-an-anyURI&apos;
return 
  (fn:namespace-uri-from-QName(fn:QName($uri, &apos;my:name&apos;)), 
   $uri castable as xs:anyURI)

fn:QName appears to do no checking that its first argument ($paramURI) is castable as xs:anyURI.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35839</commentid>
    <comment_count>1</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2010-05-26 21:59:50 +0000</bug_when>
    <thetext>This area is a total minefield.

First, the rules for exactly what is allowed in an xs:anyURI are far from clear. XSD 1.1 gives up on this, and says any sequence of Unicode characters is allowed.

Secondly, the namespaces specs (both 1.0 and 1.1) are not prescriptive about exactly what&apos;s allowed in a namespace name (&quot;URI&quot;). They talk about it being a URI/IRI respectively, but they never say that a document is ill-formed if the namespace name isn&apos;t a valid URI/IRI. So parsing a well-formed document can produce an XDM model in which there are namespace names that are not valid URIs.

To further muddy the waters, xs:anyURI allows relative URI references, which are strongly deprecated as namespace names, but nevertheless legal.

For these reasons, the XQuery spec states in regard to URILiterals (as used in namespace declarations) that &quot;However, an implementation MAY raise a static error [err:XQST0046] if the value of a URILiteral is of nonzero length and is not in the lexical space of xs:anyURI.&quot; - that is, it&apos;s up to implementations how much checking to do, and what rules to enforce. With XSD 1.1, there are no restrictions left to enforce.

At the most, fn:QName should be permissive about the checking that is done, along the same lines as the rules for URILiteral in XQuery.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35841</commentid>
    <comment_count>2</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2010-05-27 08:04:15 +0000</bug_when>
    <thetext>Would you therefore suggest changing the signatures of

fn:namespace-uri-from-QName($arg as xs:QName?) as xs:anyURI

fn:namespace-uri-for-prefix($prefix as xs:string?, 
                            $element as element()) as xs:anyURI?

fn:namespace-uri() as xs:anyURI

and

fn:namespace-uri($arg as node()?) as xs:anyURI

to return xs:string or xs:string? as appropriate?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>35842</commentid>
    <comment_count>3</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2010-05-27 10:01:33 +0000</bug_when>
    <thetext>Interestingly, this is an area where XSLT and XQuery differ in their behaviour.  I note that XSLT specifically bothers to check the namespaces for xsl:element, xsl:attribute and xsl:namespace instructions.

ERR XTDE0835

    It is a non-recoverable dynamic error if the effective value of the namespace attribute [of the xsl:element instruction] is not in the lexical space of the xs:anyURI data type.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>37252</commentid>
    <comment_count>4</comment_count>
    <who name="Tim Mills">tim</who>
    <bug_when>2010-08-05 12:39:48 +0000</bug_when>
    <thetext>There is also a related issue in fn:base-uri.

declare base-uri &apos;http://www.example.org/&apos;;

let $x := &lt;x xml:base=&quot;%gg&quot; /&gt;
return base-uri($x)

In XQuery 1.0: An XML Query Language, 3.7.1.3 Content

# base-uri is set to the following value:

   1.      If the constructed node has an attribute named xml:base, then the value of this attribute, resolved if it is relative against the base URI in the static context. The value of the xml:base attribute is normalized as described in [XML Base].
   2.      Otherwise, the value of the base URI in the static context.

I can&apos;t put my finger on anything in XQuery which says that 

declare base-uri &apos;http://www.example.org/&apos;;

&lt;x xml:base=&quot;%gg&quot; /&gt;

will raise an error before we hit the call to base-uri.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>39285</commentid>
    <comment_count>5</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2010-09-24 14:28:26 +0000</bug_when>
    <thetext>I propose to bring F+O into line with XQuery by stating: 

&quot;If &lt;code&gt;$paramURI&lt;/code&gt; is not a valid URI (XML Namespaces 1.0) or IRI (XML Namespaces 1.1) then an error &lt;rfc2119&gt;may&lt;/rfc2119&gt; be raised &lt;errorref class=&quot;CA&quot; code=&quot;0002&quot;/&gt;.&quot;

Michael Kay</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>42715</commentid>
    <comment_count>6</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2010-11-23 10:18:17 +0000</bug_when>
    <thetext>The working group has actioned me to close this (A-451-02) with the resolution described in comment #5.

I recognize that this is only a local fix; the general problem of deciding whether and when we enforce URI-validity is not going to go away easily. If the current situation is unsatisfactory, it&apos;s not for want of effort.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>66155</commentid>
    <comment_count>7</comment_count>
    <who name="Michael Kay">mike</who>
    <bug_when>2012-03-27 23:25:41 +0000</bug_when>
    <thetext>I note that the agreed change appears in the draft F+O 3.0 specification, but not in the 1.0/2.0 Second Edition. I have added a reference to this bug to the candidate errata list for any future issue of the 1.0/2.0 specification (in the xsl-query-specs CVS area), and having done so, I am now marking the bug as closed.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>