eXist-db / exist

eXist Native XML Database and Application Platform
https://exist-db.org
GNU Lesser General Public License v2.1
424 stars 179 forks source link

[BUG] few functions not according to spec #3594

Open dizzzz opened 3 years ago

dizzzz commented 3 years ago

I compared the cardinality of all (w3c defined) functions in eXist-db with the spec; I found a few differences:

eXist=contains-token#3 xs:string* xs:string xs:string? xs:boolean 
Specs=contains-token#3 xs:string* xs:string xs:string  xs:boolean

eXist=json-to-xml#1 xs:string? item()? 
Specs=json-to-xml#1 xs:string? document-node()?

eXist=json-to-xml#2 xs:string? map(*) item()? 
Specs=json-to-xml#2 xs:string? map(*) document-node()?

eXist=xml-to-json#2 node()? map(*)? xs:string? 
Specs=xml-to-json#2 node()? map(*)  xs:string?

Can these be fixed in 5.x or are these typically 6.x items?

joewiz commented 3 years ago

@dizzzz I left some notes about this in https://github.com/eXist-db/exist/pull/1929. Most notably:

But the fixes to contains-token, json-to-xml, and xml-to-json should definitely be made and I don't see any problem in making these 5.x fixes.

(By the way, I think your results might be flipped: what you say is the spec appears to be eXist's current behavior, and vice versa. For example, the specs say that fn:collection#1's parameter is xs:string?, not xs:string* - the latter is eXist's current behavior.)

joewiz commented 3 years ago

@dizzzz Your observations about the signatures of contains-token, json-to-xml, and xml-to-json are still valid. Shouldn't we keep this issue open until those issues are fixed?

lcahlander commented 1 year ago

This code

xquery version "3.1";

fn:json-to-xml(fn:serialize(fn:json-doc(file:///Users/lcahland/Desktop/foo.json, map {
    "liberal": fn:true(),
    "escape": fn:true()
}), map {
    "method": "json"
}), map {
    "liberal": fn:true(),
    "escape": fn:true()
})

with the JSON document:

{
    "operandRight": {
        "type": "literal",
        "dataType": "code",
        "value": "\u0000"
    }
}

returns the following from Saxon

<?xml version="1.0" encoding="UTF-8"?>
<map xmlns=http://www.w3.org/2005/xpath-functions>
   <map key="operandRight">
      <string key="dataType">code</string>
      <string key="value" escaped="true">\\u0000</string>
      <string key="type">literal</string>
   </map>
</map>

And this from eXist-db 6.0.1. The value in <fn:string key="value"></fn:string> is a unicode 0x0 and will not store in the database

<fn:map xmlns:fn=http://www.w3.org/2005/xpath-functions>
  <fn:map key="operandRight">
    <fn:string key="type">literal</fn:string>
    <fn:string key="dataType">code</fn:string>
    <fn:string key="value"></fn:string>
  </fn:map>
</fn:map>
line-o commented 1 year ago

@lcahlander The issue valid but does not have to do with cardinalities. I would suggest to open a separate issue for your finding and rename this issue to mention built-in function cardinality explicitly. My fear is that we will forget to fix your issue when it is in here and other may also not find it.