Executing lib_only query invokes URI resolution process

Bug #992304 reported by Chris Hillery
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Zorba
Fix Released
Medium
Chris Hillery

Bug Description

The following query:

module namespace foo = "http://www.zorba-xquery.com/foo";

declare function foo:test() {
  if (fn:true())
  then 1
  else $a
};

(which is in the Zorba source as bin/test/mymod.xq) actually contacts www.zorba-xquery.com via HTTP and attempts to download /foo.xq. This means that the module namespace URI is undergoing URI resolution. I cannot imagine why this would be the case, but it leads not only to slowness but can cause the query to change behaviour depending on what www.zorba-xquery.com chooses to return. (In the original test case, the URL was at 28msec.com, and when 28msec.com changed from raising a 404 error to returning a 200 with an error HTML page, the query started failing with a compilation error. Apparently Zorba was attempting to actually compile the HTML as an XQuery.)

Related branches

Chris Hillery (ceejatec)
Changed in zorba:
importance: Undecided → Medium
Chris Hillery (ceejatec)
summary: - module declaration invokes URI resolution process
+ Executing lib_only query invokes URI resolution process
Revision history for this message
Chris Hillery (ceejatec) wrote :

I have figured out that this only happens when compiling the query as a library module, as with the -l command-line option. This happens because Zorba actually creates a separate query that imports the module namespace and executes that, registering a custom URLResolver for that namespace URI that returns the original query.

The reason this ends up hitting the web is because the full URI mapping is also done. So, in this case, the URL "http://www.zorba-xquery.com/foo" gets turned into a number of candidate URIs, one of which is "http://www.zorba-xquery.com/foo.xq". The custom URLResolver recognizes only the original unchanged URI, so it returns nothing for this URI, letting Zorba fall through to the built-in URLResolvers including the HTTPURLResolver.

The fix is easy enough - simplify the custom URLResolver so it doesn't even check the URL it is passed. We know it will always be the URL we are expecting, even if it's been modified by URI Mapping, so we can just return the query file resource directly. Tested locally and this works.

Changed in zorba:
assignee: nobody → Chris Hillery (ceejatec)
Changed in zorba:
milestone: none → 2.5
Chris Hillery (ceejatec)
Changed in zorba:
milestone: 2.5 → 2.8
Chris Hillery (ceejatec)
Changed in zorba:
status: New → Fix Committed
status: Fix Committed → Fix Released
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.