Project

Profile

Help

Bug #2885

Use of URI.js

Added by Debbie Lockett almost 2 years ago. Updated 10 months ago.

Status:
Closed
Priority:
Low
Assignee:
-
Sprint/Milestone:
-
Start date:
2016-08-18
Due date:
% Done:

100%

Applies to JS Branch:
0.9
Fix Committed on JS Branch:
0.9
Fixed in JS Release:
SEF Generated with:
Company:
-
Contact person:
-
Additional contact persons:
-

Description

To what extent is this library still used? Can its use be replaced, and the library removed from the built SaxonJS.js?

See comments in the documentation:

http://www.saxonica.com/saxon-js/documentation/index.html#!conditions/third-party-components

History

#1 Updated by Michael Kay over 1 year ago

I believe the places we use the URI library are:

(a) to implement the resolve-uri() function (CoreFn.js)

(b) in DOMUtils, (baseURI function) to test whether a URI is absolute (and then resolve it if not)

(c) when initiating the transformation, to resolve the supplied stylesheet URI against the URI of the HTML page

When we're in the browser, I think it makes sense to try the resolve-uri() method given here:

http://stackoverflow.com/questions/470832/getting-an-absolute-url-from-a-relative-one-ie6-issue

specifically

function resolve(url, base_url) {
  var doc      = document
    , old_base = doc.getElementsByTagName('base')[0]
    , old_href = old_base && old_base.href
    , doc_head = doc.head || doc.getElementsByTagName('head')[0]
    , our_base = old_base || doc_head.appendChild(doc.createElement('base'))
    , resolver = doc.createElement('a')
    , resolved_url
    ;
  our_base.href = base_url || '';
  resolver.href = url;
  resolved_url  = resolver.href; // browser magic at work here

  if (old_base) old_base.href = old_href;
  else doc_head.removeChild(our_base);
  return resolved_url;
}

This essentially adds a <base> element to the header of the HTML page, and creates an <a> element containing the relative URI, and then piggy-backs on the fact that the browser knows how to resolve relative URIs in <a> elements.

We should give this a try. We would still need to use the URI.js library in non-browser environments.

#2 Updated by Michael Kay over 1 year ago

  • Tracker changed from Feature to Bug

#3 Updated by Debbie Lockett over 1 year ago

  • Status changed from New to Resolved

BrowserPlatform now has resolveUri method as suggested above. (Note that the JSTestDriver platform used for Nashorn also has a resolveUri method.)

The use of URI.js has now been removed, basically we now use this platform resolveUri method:

(a) resolve-uri() function in CoreFn.js: now does some basic testing that the supplied parameters are valid, then uses the platform.resolveUri method.

(b) baseURI() method in DomUtils: added DomUtils.isAbsoluteURI method which uses regex to check that a string is an absolute URI. Then use platform.resolveUri

(c) initiating transform: in browser uses resolveUri

#4 Updated by Debbie Lockett over 1 year ago

  • Status changed from Resolved to Closed
  • % Done changed from 0 to 100
  • Fixed in version set to 0.9.1

Bug fix applied in the Saxon-JS 0.9.1 beta release.

#5 Updated by Community Admin 10 months ago

  • Fixed in JS Release set to Saxon-JS 0.9.1
  • Applies to JS Branch 0.9 added
  • Fix Committed on JS Branch 0.9 added

Please register to edit this issue

Also available in: Atom PDF Tracking page