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

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/resolve-external.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +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);
withoutHash = url.removeFileProtocol(withoutHash);
obj.$ref = withoutHash + obj.$ref;
obj.$ref = url.toFileSystemPath(withoutHash) + obj.$ref;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As @matthewmurphy and the other speed-runners say, "First try!" 😆

}

for (let key of Object.keys(obj)) {
Expand Down
28 changes: 0 additions & 28 deletions lib/util/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,34 +240,6 @@ 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.removeFileProtocol(filePath) + entry.$ref;
url.toFileSystemPath(filePath) + entry.$ref;
}
continue;
} else {
Expand Down