Skip to content

[BUG] Static base URI returned by static-base-uri() is not the URI of the entity and is not an absolute URI #4517

@cmsmcq

Description

@cmsmcq

Describe the bug
When an XQuery module evaluated within Oxygen calls the static-base-uri() function, the value returned ("/db") is not the URI of the query module and is not an absolute URI.

When the same module (or at least, as close to "the same" as cut and paste can manage) is evaluated within exide, no value is returned.

Expected behavior
The expected behavior of static-base-uri() is to return the base URI in the static context. This is defined by XPath 3.1, sec. 2.1.1 as "an absolute URI, used to resolve relative URI references".

XQuery sec. 4.5 explains that the static base URI can be set by the user and that if not set by the user it defaults (to put it informally) to the location of the query module:

If no base URI declaration is present, Static Base URI property is established according to the principles outlined in [RFC3986] Section 5.1—that is, it defaults first to the base URI of the encapsulating entity, then to the URI used to retrieve the entity, and finally to an implementation-defined default.

To Reproduce
In Oxygen, after setting things up as described in the eXist-db documentation, create an XQuery file with the following content:

xquery version "3.1";

<tests>
    <static-base-uri>{ static-base-uri() }</static-base-uri>
    <does-sbu-exist>{ exists(static-base-uri()) }</does-sbu-exist>
    <rel>{ resolve-uri('#foobar') }</rel>
    <rel>{ resolve-uri('#foobar', static-base-uri() ) }</rel>  
</tests>

On my system, this returns

<tests>
    <static-base-uri>/db</static-base-uri>
    <does-sbu-exist>true</does-sbu-exist>
    <rel>/db#foobar</rel>
    <rel>/db#foobar</rel>
</tests>

As a side note: in exide, this returns an error report:

<exception>
    <path>/db/tmp/uri-testing.xq</path>
    <message>
      err:FONS0005 base URI of the static context has not been assigned a value. [at line 7, column 12, source: /db/tmp/uri-testing.xq]
    </message>
</exception>

If the two rel elements are commented out, it returns

<tests>
    <static-base-uri/>
    <does-sbu-exist>false</does-sbu-exist>
    <!--
        <rel>{ resolve-uri('#foobar') }</rel>
        <rel>{ resolve-uri('#foobar', static-base-uri() ) }</rel>
    -->
</tests>

Discussion

There are several distinct problems in the current behavior:

  • In exide, the static base URI property appears not to be set (so that attempts to use the static base URI by calling resolve-uri() fail with error FONS0005) -- even though the context provided in the exception makes clear that eXist does have access to a path to the enclosing query module and thus to a URI for the module, and so could (and on my reading of the text quoted above, MUST) give the property a useful value. On this point compare issue [BUG] No base-uri assigned to static context in REST request. #4242.
  • In Oxygen, the static base URI property is set to a relative URI reference (/db), which is by definition not an absolute URI and thus does not match the description in the spec.
  • If I am reading the XQuery spec correctly, conforming processors are required to set the static base URI as described above, which means with a URI for the query module, supposing that it has one. The test module I am using does have a URI, and unless the exist interface to Oxygen makes that URI inaccesible, eXist should use it as the static base URI. (Other query processors running within Oxygen appear to have access to the URI; I supposed that eXist does, too.)

N.B. It is not, strictly speaking, non-conforming for the static base URI property to be unset, or to be set to a value that is not the URI of the query module; both the XQuery spec and the relevant RFCs foresee the possibility of resources (here query modules) for which no URI is available. But all the relevant specs seem to be clear that this is an undesirable situation, and I think they make clear that a good-faith effort to identify the appropriate base URI is required for conformance. Since when running the query from exide, eXist clearly does have a path for the query and so can construct a URI for it, I think the failure to set the static base URI property is a bug. I don't know what information passes between Oxygen and eXist, so I do not know for a fact that in that case eXist has access to the URI for the query module -- but other query processors appear to have access to it, so I expect eXist can get access to it.

The failure to set the static base URI property properly is currently troubling me because it is making it harder for me to make a set of library modules work in eXist.

Context (please always complete the following information):

  • OS: Pop!_OS 22.04 LTS
  • eXist-db version: [e.g. 6.0.1]
  • Java Version: java -version returns

openjdk version "11.0.16" 2022-07-19
OpenJDK Runtime Environment (build 11.0.16+8-post-Ubuntu-0ubuntu122.04)
OpenJDK 64-Bit Server VM (build 11.0.16+8-post-Ubuntu-0ubuntu122.04, mixed mode, sharing)

Additional context

  • How is eXist-db installed? from exist-installer-6.0.1.jar (as downloaded 18 March 2022)
  • Any custom changes in e.g. conf.xml? No.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions