Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/CI-CD.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
matrix:
os:
- ubuntu-latest # Chrome, Firefox
- windows-latest # Internet Explorer
- windows-latest # Edge

steps:
- name: Checkout source
Expand Down
6 changes: 1 addition & 5 deletions lib/resolve-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,7 @@ function crawl (obj, path, $refs, options, external, seen) {
if (external && $Ref.is$Ref(obj)) {
/* Correct the reference in the external document so we can resolve it */
let withoutHash = url.stripHash(path);
const isFileUrl = withoutHash.substr(0, 7).toLowerCase() === "file://";
if (isFileUrl) {
// Strip-off the protocol
withoutHash = withoutHash.substr(7);
}
withoutHash = url.removeFileProtocol(withoutHash);
obj.$ref = withoutHash + obj.$ref;
}

Expand Down
28 changes: 28 additions & 0 deletions lib/util/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,34 @@ exports.toFileSystemPath = function toFileSystemPath (path, keepFileProtocol) {
return path;
};

/**
* Removes file protocol from path.
*
* @param {string} path
* @returns {string}
*/
exports.removeFileProtocol = function removeFileProtocol (path) {
// Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
path = decodeURI(path);

// Step 2: Manually decode characters that are not decoded by `decodeURI`.
// This includes characters such as "#" and "?", which have special meaning in URLs,
// but are just normal characters in a filesystem path.
for (let i = 0; i < urlDecodePatterns.length; i += 2) {
path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
}

// Step 3: If it's a "file://" URL, then format it consistently
// or convert it to a local filesystem path
let isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
if (isFileUrl) {
// Strip-off the protocol, and the initial "/", if there is one
path = path.substr(7);
}

return path;
};

/**
* Converts a $ref pointer to a valid JSON Path.
*
Expand Down
2 changes: 1 addition & 1 deletion test/utils/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const helper = (module.exports = {
if (typeof entry.$ref === "string") {
if (entry.$ref.startsWith("#")) {
clonedExpected[i].$ref =
url.toFileSystemPath(filePath) + entry.$ref;
url.removeFileProtocol(filePath) + entry.$ref;
}
continue;
} else {
Expand Down