From 13e8ae1c36ad34456d8526001949c6de628c7d12 Mon Sep 17 00:00:00 2001 From: Eric Prud'hommeaux Date: Mon, 25 Nov 2019 11:39:01 +0100 Subject: [PATCH 1/2] @context resolution respects relative URLs. c.f. w3c/json-ld-api#228 --- lib/context.js | 10 +++++----- lib/documentLoaders/node.js | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/context.js b/lib/context.js index bb33d82f..7f3b73ac 100644 --- a/lib/context.js +++ b/lib/context.js @@ -1174,12 +1174,12 @@ async function _retrieveContextUrls(input, options) { const {documentLoader} = options; // retrieve all @context URLs in input - await retrieve(input, new Set(), documentLoader); + await retrieve(input, new Set(), documentLoader, options.base); return input; // recursive function that will retrieve all @context URLs in documents - async function retrieve(doc, cycles, documentLoader) { + async function retrieve(doc, cycles, documentLoader, baseUrl) { if(cycles.size > MAX_CONTEXT_URLS) { throw new JsonLdError( 'Maximum number of @context URLs exceeded.', @@ -1189,7 +1189,7 @@ async function _retrieveContextUrls(input, options) { // find all URLs in the given document const urls = new Map(); - _findContextUrls(doc, urls, false, options.base); + _findContextUrls(doc, urls, false, baseUrl); if(urls.size === 0) { return; } @@ -1256,13 +1256,13 @@ async function _retrieveContextUrls(input, options) { } // recurse - await retrieve(ctx, _cycles, documentLoader); + await retrieve(ctx, _cycles, documentLoader, url); // store retrieved context w/replaced @context URLs urls.set(url, ctx['@context']); // replace all @context URLs in the document - _findContextUrls(doc, urls, true, options.base); + _findContextUrls(doc, urls, true, baseUrl); })); } } diff --git a/lib/documentLoaders/node.js b/lib/documentLoaders/node.js index a00a332c..abbc457c 100644 --- a/lib/documentLoaders/node.js +++ b/lib/documentLoaders/node.js @@ -83,7 +83,7 @@ module.exports = ({ const statusText = http.STATUS_CODES[res.statusCode]; if(res.statusCode >= 400) { throw new JsonLdError( - 'URL could not be dereferenced: ' + statusText, + 'URL ' + url + ' could not be dereferenced: ' + statusText, 'jsonld.InvalidUrl', { code: 'loading document failed', url, From fa65b0524168f5aa02b8aef22cabe745638352fd Mon Sep 17 00:00:00 2001 From: Eric Prud'hommeaux Date: Tue, 3 Dec 2019 15:23:22 +0100 Subject: [PATCH 2/2] Update lib/documentLoaders/node.js Co-Authored-By: Dave Longley --- lib/documentLoaders/node.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/documentLoaders/node.js b/lib/documentLoaders/node.js index abbc457c..e429a0d2 100644 --- a/lib/documentLoaders/node.js +++ b/lib/documentLoaders/node.js @@ -83,7 +83,7 @@ module.exports = ({ const statusText = http.STATUS_CODES[res.statusCode]; if(res.statusCode >= 400) { throw new JsonLdError( - 'URL ' + url + ' could not be dereferenced: ' + statusText, + `URL "${url}" could not be dereferenced: ${statusText}`, 'jsonld.InvalidUrl', { code: 'loading document failed', url,