XQXQ should set base URI of execution context

Bug #1133806 reported by Chris Hillery
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zorba
Fix Committed
Medium
Juan Zacarias

Bug Description

import module namespace xqxq = "http://www.zorba-xquery.com/modules/xqxq";

variable $q := xqxq:prepare-main-module("fn:static-base-uri()");
fn:static-base-uri(), xqxq:evaluate($q)

Assuming this query is saved in a file /tmp/foo.xq, this query returns

file:///tmp/foo.xq file:///

In other words, the static context's base-uri is unset by XQXQ.

I think a reasonable solution would be for XQXQ to call StaticContext::setBaseURI() on the static context it creates, passing through the base URI of the static context of the query that invokes it (assuming that it's possible to obtain that information).

Related branches

Chris Hillery (ceejatec)
Changed in zorba:
assignee: nobody → Juan Zacarias (juan457)
importance: Undecided → Medium
status: New → Confirmed
Revision history for this message
Juan Zacarias (juan457) wrote :

This information is not available for the module since the base URI present when the module takes action is the base URI of the module "http://www.zorba-xquery.com/modules/xqxq"

What I could do is add a parameter to set a base URI, or probably there could be a way to patch zorba to send the correct base URI to the module but that would be an ugly an invasive solution.

Juan Zacarias (juan457)
Changed in zorba:
status: Confirmed → In Progress
Revision history for this message
Juan Zacarias (juan457) wrote :

I made a rough implementation of how to solve this, though is rally invasive and don't know if there is an other way of getting the main query base URI into the module.

Revision history for this message
Chris Hillery (ceejatec) wrote :

I agree, the proposed solution is fairly invasive and hacky, although it does get the job done.

Now that we are at Zorba 3.0, however, we have a better solution: add additional (optional) arguments to ContextualExternalFunction::evaluate() so we can pass the Static and Dynamic Contexts of the *caller* to external functions. eg:

class ZORBA_DLL_PUBLIC ContextualExternalFunction : public ExternalFunction
{
  virtual ItemSequence_t
  evaluate(
      const Arguments_t&,
      const StaticContext* aModuleSctx,
      const DynamicContext* aModuleDctx,
      const StaticContext* aCallingSctx,
      const DynamicContext* aCallingDctx) const = 0;

The only slightly ugly bit is that this is a virtual function, intended to be overridden by user-provided subclasses. We have two choices:

1. Provide just the above signature. This would force every user-created ContextualExternalFunction implementation to be re-written to match the new signature.

2. Continue providing the old signature as well as the new one. Users could override either one depending on their needs. In that case, we would need to provide a stub implementation of the original signature that returned some sentinel value (and make that method non-pure virtual). The implementation of FnCallIterator would call the first, see if the return value matched the sentinel, and if so call the second.

I prefer solution (2) *if* it doesn't imply a significant performance overhead.

Revision history for this message
Sorin Marian Nasoi (sorin.marian.nasoi) wrote :

This is orthogonal to the discussion because it relates to FOTS driver and FOTS the main consumers of XQXQ.

As far as W3C is concerned, they agreed that some test-cases assume that the base-uri is assumed to be set to the file that contains the test-case (typically this is the test-set).

They addressed the issue in
https://www.w3.org/Bugs/Public/show_bug.cgi?id=22279

As a result I have opened lp:1187807.

Until XQXQ will provide a nice way of exposing the static and dynamic contextes, I will update FOTS driver to add in the prolog of the test-case the setting of base-uri.

Revision history for this message
Chris Hillery (ceejatec) wrote :

My original idea was to pass through the base URI of the query invoking ZQ. However, even that wouldn't have helped FOTS driver as it happens. So, it seems that nobody really needs this fix after all.

Juan proposed a change which at least causes the base URI to be something valid, namely the ZQ module URI. I'm merging that and claiming this bug is fixed.

Chris Hillery (ceejatec)
Changed in zorba:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.