whitlockjc / json-refs

Various utilities for JSON Pointers (http://tools.ietf.org/html/rfc6901) and JSON References (http://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03).
MIT License
226 stars 64 forks source link

JsonRefsOptions location set to relative path containing more than 1 level generates invalid fqURI #189

Open gilmcquillan opened 3 years ago

gilmcquillan commented 3 years ago

Notice on https://github.com/whitlockjc/json-refs/blob/master/index.js#L101

function combineURIs (u1, u2) {
  ...
  return (remoteUriTypes.indexOf(combinedDetails.reference) === -1 &&
->          combinedDetails.path.indexOf('../') === 0 ? '../' : '') + URI.serialize(combinedDetails);

combinedDetails.path.indexOf('../') === 0 ? '../' : '' has the effect of changing location values starting with ../../../foobar to ../foobar.

My current work around in node is to prepend the result of process.cwd() + '/' to the location.

const jsonRefsOptions = location => {
    return {
      filter: ['relative', 'remote'],
      loaderOptions: {
        processContent: (res, callback) => {
          callback(null, YAML.load(res.text));
        }
      },
      location: `${process.cwd()}/${location}`,
      includeInvalid: true
    };
  };