Skip to content

Commit 8d19b3b

Browse files
authored
Merge pull request #52 from stoplightio/fix/2385-external-ref-resolution
process refs through fileSystemPath to account for os & browser
2 parents f6c013d + 15d4514 commit 8d19b3b

File tree

3 files changed

+2
-31
lines changed

3 files changed

+2
-31
lines changed

lib/resolve-external.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ function crawl (obj, path, $refs, options, external, seen) {
7575
if (external && $Ref.is$Ref(obj)) {
7676
/* Correct the reference in the external document so we can resolve it */
7777
let withoutHash = url.stripHash(path);
78-
withoutHash = url.removeFileProtocol(withoutHash);
79-
obj.$ref = withoutHash + obj.$ref;
78+
obj.$ref = url.toFileSystemPath(withoutHash) + obj.$ref;
8079
}
8180

8281
for (let key of Object.keys(obj)) {

lib/util/url.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -240,34 +240,6 @@ exports.toFileSystemPath = function toFileSystemPath (path, keepFileProtocol) {
240240
return path;
241241
};
242242

243-
/**
244-
* Removes file protocol from path.
245-
*
246-
* @param {string} path
247-
* @returns {string}
248-
*/
249-
exports.removeFileProtocol = function removeFileProtocol (path) {
250-
// Step 1: `decodeURI` will decode characters such as Cyrillic characters, spaces, etc.
251-
path = decodeURI(path);
252-
253-
// Step 2: Manually decode characters that are not decoded by `decodeURI`.
254-
// This includes characters such as "#" and "?", which have special meaning in URLs,
255-
// but are just normal characters in a filesystem path.
256-
for (let i = 0; i < urlDecodePatterns.length; i += 2) {
257-
path = path.replace(urlDecodePatterns[i], urlDecodePatterns[i + 1]);
258-
}
259-
260-
// Step 3: If it's a "file://" URL, then format it consistently
261-
// or convert it to a local filesystem path
262-
let isFileUrl = path.substr(0, 7).toLowerCase() === "file://";
263-
if (isFileUrl) {
264-
// Strip-off the protocol, and the initial "/", if there is one
265-
path = path.substr(7);
266-
}
267-
268-
return path;
269-
};
270-
271243
/**
272244
* Converts a $ref pointer to a valid JSON Path.
273245
*

test/utils/helper.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ const helper = (module.exports = {
8383
if (typeof entry.$ref === "string") {
8484
if (entry.$ref.startsWith("#")) {
8585
clonedExpected[i].$ref =
86-
url.removeFileProtocol(filePath) + entry.$ref;
86+
url.toFileSystemPath(filePath) + entry.$ref;
8787
}
8888
continue;
8989
} else {

0 commit comments

Comments
 (0)