kota65535 / openapi-merger

Merges multiple OpenAPI document files into a single file.
MIT License
32 stars 6 forks source link

Bad replacement in parseUrl #85

Closed haata closed 1 year ago

haata commented 1 year ago

This one took me a long time to figure out, fun quirks of node.js.... I'll try to come up with a PR, but I'm not familiar with javascript so I probably won't have the entire context here.

From parseUrl() in util.js.

function parseUrl(url) {
  // this converts to posix path (separated by '/') if windows path (separated by '\') is given
  const ret = Url.parse(url);
  ret.isLocal = !ret.path && ret.hash;
  ret.isHttp = ret.protocol && ret.protocol.match(/^(http|https):/);
  ret.hrefWoHash = ret.href.replace(ret.hash, "");
  if (ret.hash) {
    // for windows
    ret.hash = ret.hash.replace(/%5C/g, "/");
  }
  return ret;
}

If your CWD has the string null in it, the path will be mangled.

For example, if I run the command in a directory that looks like myspecialdir/bug12345_null_ptr_fix, this function will change all URLs to myspecialdir/bug12345__ptr_fix. This is because javascript treats ret.hash as a string in this particular case...

In my case the url looks like this /da/main2/build/abbbbbb/ccc_dddddd_eee_ffff_ggggggg_null_not_blank.proto.linux.amd64.release.current/Prod/IRR/PublicApis/vcdr/v1alpha/yaml/vcdr_openapi_main.yaml.