Skip to content

Commit 86ad38e

Browse files
committed
fix bug in test helper
1 parent 9f37789 commit 86ad38e

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

.github/workflows/CI-CD.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ jobs:
6767
matrix:
6868
os:
6969
- ubuntu-latest # Chrome, Firefox
70-
- windows-latest # Internet Explorer
70+
- windows-latest # Edge
7171

7272
steps:
7373
- name: Checkout source

lib/resolve-external.js

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +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-
const isFileUrl = withoutHash.substr(0, 7).toLowerCase() === "file://";
79-
if (isFileUrl) {
80-
// Strip-off the protocol
81-
withoutHash = withoutHash.substr(7);
82-
}
78+
withoutHash = url.removeFileProtocol(withoutHash);
8379
obj.$ref = withoutHash + obj.$ref;
8480
}
8581

lib/util/url.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,34 @@ 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+
243271
/**
244272
* Converts a $ref pointer to a valid JSON Path.
245273
*

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.toFileSystemPath(filePath) + entry.$ref;
86+
url.removeFileProtocol(filePath) + entry.$ref;
8787
}
8888
continue;
8989
} else {

0 commit comments

Comments
 (0)