json-schema-ref-parser icon indicating copy to clipboard operation
json-schema-ref-parser copied to clipboard

Custom resolver casing change

Open davidkelley opened this issue 7 years ago • 5 comments

Hi, thanks for the really great library. However, I think I have spotted a bug and can't seem to figure out where/why it's happening. Given an object like this:

{
  "$ref": "custom://Path/Is/Case/Sensitive"
}

And a custom resolver like the following:

module.exports = {
  order: 1,

  canRead: /^custom:\/\//i,

  read: function(file) {
    console.log(file.url);
    ...
  },
  ...
}

The url value logged to the console would be: "custom://path/Is/Case/Sensitive", note the p casing change. Is this something I'm doing or possibly a bug?

davidkelley avatar Sep 22 '17 13:09 davidkelley

Thanks for reporting this. It does indeed appear to be a bug. I've reproduced it here: https://runkit.com/bigstickcarpet/json-schema-ref-parser-issue-49

JamesMessinger avatar Sep 22 '17 18:09 JamesMessinger

Morning, any news on this ?

setheal avatar Feb 18 '21 10:02 setheal

@setheal Please try and recreate and if you can a pull request would be very welcome.

philsturgeon avatar Feb 18 '21 11:02 philsturgeon

I'm seeing a version of the same issue. If my $ref is template:personName.template then the file URL I get is 'personname.template', i.e. the whole thing is lower cased. Any chance of it being fixed?

chrimc62 avatar May 06 '21 01:05 chrimc62

Looks like the fundamental issue is that the package assumes it is a URL (not just a URI) unless it is javascript: which in the static hostlessProtocol list found in url.js. I can see two ways to fix this:

  1. Allow people to specify a protocol is hostless in the options.
  2. Not assume it is a URL.

chrimc62 avatar May 06 '21 02:05 chrimc62